Error recording Date

setis

Registered User.
Local time
Today, 05:15
Joined
Sep 30, 2017
Messages
127
I'm trying to use a button to record the actual date and time on a field on my form.
I'm using simple vba (below) but I am getting an error (see attached).

Code:
Private Sub Now_Click()
Me.CreatedOn.SetFocus
Me.CreatedOn = Now()
End Sub

The field on the table is formated as "General Date" and I am use the same procedure in other forms in the same DB without issues. Can this be a form issue?
 

Attachments

  • dateerror.PNG
    dateerror.PNG
    4.7 KB · Views: 91
You don't need to set focus to the control to set it value.
In fact it can cause other problems.

Try it without that first. If not what is the format set in the control of the form?
 
You don't need to set focus to the control to set it value.
In fact it can cause other problems.

Try it without that first. If not what is the format set in the control of the form?

Done and I get the same error, the format in the control is "General Date"
 
Doy you have Expression as control source.
 
Wht do you need to set it on a click if a botton. You can set it at the form before update event.
 
If this is for new records just set the default value on the form to Now() ?

In fact you can do that on the table and you then don't even need the field on the form at all...
 
Wht do you need to set it on a click if a botton. You can set it at the form before update event.

The team will be registering cases backward and they will have to put dates from last month. I just want to have the option to have a "Now" button for current cases.
 
So if you go to the table can you enter a datetime without an issue ?

If you can - I would delete the control on the form. Save the form compact and repair. Then reopen the form and create a new text box. Call it txtCreatedDate and add you code back in.

Sometimes controls get corrupted.
 
So if you go to the table can you enter a datetime without an issue ?

If you can - I would delete the control on the form. Save the form compact and repair. Then reopen the form and create a new text box. Call it txtCreatedDate and add you code back in.

Sometimes controls get corrupted.

Thanks! It's weird. Did this before (without the compact and repair though) and did't worked. Now it does!

Thanks a lot!
 

Users who are viewing this thread

Back
Top Bottom