I have a txtbox called txtDate and I want to populate it with the current date. Something like this but it's not workingVB Code:
Me.txtDate.Text = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM")
Printable View
I have a txtbox called txtDate and I want to populate it with the current date. Something like this but it's not workingVB Code:
Me.txtDate.Text = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM")
this works for my label but how do I get it to work for the txtboxVB Code:
Me!lblClock.Caption = Format(Now, "dddd, mmm d yyyy, hh:mm AMPM")
What error do you get (or what is the result of calling the code) ?
This code works just fine for me. The result that I get is: Friday, Sep 9 2005, 07:19 AMQuote:
Originally Posted by vonoventwin
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.Quote:
Originally Posted by yrwyddfa
vonoventwin: Why are you using Me and how is it not working.
"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?Quote:
Originally Posted by RobDog888
Oh, ok. Then your using Access VBA (Visual Basic for Applications). ;)
VBA is also located in Word, Excel, FrontPage, Outlook, and PowerPoint.
Quote:
Originally Posted by vonoventwin
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.
Turns out to be a VBA question. Moved to Office Development.
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?Quote:
Originally Posted by vonoventwin
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.
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!
The .Text and .Value properties are usually interchangeable but can sometimes contain different values. Is this a bound textbox?
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?
I had to make it Me.txtDate = Now, the Value for the the feild in the table is Date/Time that's why!