Get todays date/time on click in Textbox

jpl458

Well-known member
Local time
Today, 05:21
Joined
Mar 30, 2012
Messages
1,218
Been away from VBA for a while, relearning. Have a textbox and when I clicking the textbox I want the Date to appear. Using following in onclick event for the textbox;

Private Sub datebox_Click()
datebox.Value = Date
End Sub

I get Method or data member not found.

Thanks
 
Should be fine, but try it this way.
Code:
Me.Datebox = Now()
 
I would use dbl-click rather than click and I would not just overlay the existing data.
Code:
If IsDate(Me.DateBox) Then
    If Msgbox("Do you want to overlay the existing date?",vbYesNo) = vbYes Then
        Me.DateBox = Now()
    End If
Else
    Me.DateBox = Now()
End IF

Also, you might not actually want to force the user to do this. If the date is intended to record when the record got added, you should populate it yourself in the Form's BeforeUpdate event rather than having the user do it. Then you can lock the field and prevent the user from ever changing the value.
 

Users who are viewing this thread

Back
Top Bottom