|
-
Sep 9th, 2005, 06:13 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] EASY quick question
I have a txtbox called txtDate and I want to populate it with the current date. Something like this but it's not working
VB Code:
Me.txtDate.Text = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM")
-
Sep 9th, 2005, 06:14 AM
#2
Thread Starter
Hyperactive Member
Re: EASY quick question
this works for my label but how do I get it to work for the txtbox
VB Code:
Me!lblClock.Caption = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM")
-
Sep 9th, 2005, 06:17 AM
#3
Frenzied Member
Re: EASY quick question
What error do you get (or what is the result of calling the code) ?
"As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein
It's turtles! And it's all the way down
-
Sep 9th, 2005, 06:19 AM
#4
Re: EASY quick question
 Originally Posted by vonoventwin
I have a txtbox called txtDate and I want to populate it with the current date. Something like this but it's not working
VB Code:
Me.txtDate.Text = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM")
This code works just fine for me. The result that I get is: Friday, Sep 9 2005, 07:19 AM
-
Sep 9th, 2005, 06:20 AM
#5
Frenzied Member
Re: EASY quick question
I suspect it's a scope thing going on with the 'Me' bit
"As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Albert Einstein
It's turtles! And it's all the way down
-
Sep 9th, 2005, 06:23 AM
#6
Re: EASY quick question
 Originally Posted by yrwyddfa
I suspect it's a scope thing going on with the 'Me' bit
Ahhhh...me thinks you may have hit on something as I didn't use the Me keyword.
vonoventwin: Why are you using Me and how is it not working.
-
Sep 9th, 2005, 08:09 AM
#7
Re: EASY quick question
"Me!lblClock.Caption" is a Access Forms format. Are you using an Access form or VB 6.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 9th, 2005, 08:16 AM
#8
Thread Starter
Hyperactive Member
Re: EASY quick question
 Originally Posted by RobDog888
"Me!lblClock.Caption" is a Access Forms format. Are you using an Access form or VB 6.
As far as I know I don't even have VB on my computer, just whatever is in with Access. Is that VB?
-
Sep 9th, 2005, 08:18 AM
#9
Re: EASY quick question
Oh, ok. Then your using Access VBA (Visual Basic for Applications).
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 9th, 2005, 08:21 AM
#10
Re: EASY quick question
VBA is also located in Word, Excel, FrontPage, Outlook, and PowerPoint.
-
Sep 9th, 2005, 08:29 AM
#11
Re: EASY quick question
 Originally Posted by vonoventwin
I have a txtbox called txtDate and I want to populate it with the current date. Something like this but it's not working
VB Code:
Me.txtDate.Text = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM")
I have also found that using the ".Text" Property when assigning data to a text box causes problem. This should work for you:
VB Code:
Me.txtDate = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM")
Also if you have multiple text boxes and you want to refer to them in a kind of control array you can do this:
VB Code:
Option Compare Database
Private Sub Command1_Click()
Dim a As Long
For a = 0 To 6
Me("Text" & a) = "Text Box # " & a
Next a
End Sub
This code assumes that you have seven (7) text boxes Named Text0 through Text6.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Sep 9th, 2005, 08:32 AM
#12
Re: EASY quick question
Turns out to be a VBA question. Moved to Office Development.
-
Sep 9th, 2005, 08:36 AM
#13
Thread Starter
Hyperactive Member
Re: EASY quick question
Doesnt work for me Mark...
-
Sep 9th, 2005, 08:41 AM
#14
Re: EASY quick question
 Originally Posted by vonoventwin
Doesnt work for me Mark...
What, exactly, happens when you run that code? Do you get anything? Do you get an error? If so, what is the error?
-
Sep 9th, 2005, 08:52 AM
#15
Thread Starter
Hyperactive Member
Re: EASY quick question
forms txtDate box show #Error. Now what I have even tried is to create the label (Me!lblClock.Caption = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM") which works fine and then give the txtDate box the =[lblClock].[Caption] . This used to work but I'm not sure why it doesn't anymore.
-
Sep 9th, 2005, 08:53 AM
#16
Thread Starter
Hyperactive Member
Re: EASY quick question
Well I just figured it out, I have the txtDate format as a date/time, when I change it to Text it works fine. Good enough for me!
-
Sep 9th, 2005, 08:54 AM
#17
Re: [RESOLVED] EASY quick question
The .Text and .Value properties are usually interchangeable but can sometimes contain different values. Is this a bound textbox?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 9th, 2005, 08:58 AM
#18
Re: [RESOLVED] EASY quick question
If you are getting #error it is because there is an error in the data tab of the properties form (probably a wrong formula).
Marks code would work, but it is VBA code and has to be called in the On_Load event of the form or via a click of a button.
Your error would either be in the data source or you need to put ' now() ' (without single quotes) into the properties>data tab>default value.
Post up what you have?
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Sep 9th, 2005, 09:28 AM
#19
Thread Starter
Hyperactive Member
Re: [RESOLVED] EASY quick question
I had to make it Me.txtDate = Now, the Value for the the feild in the table is Date/Time that's why!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|