Close form event - Type Mismatch

I am trying to populate a date field in a table when the user clicks the close form command button and has made a change in the data on the form.

Here is my code but I am getting a type mismatch error.

    If Me.DataChange = True Then
        Me.txtRevDate = Now()
    End If
Who is Participating?
PatHartmanConnect With a Mentor Commented:
The code belongs in the Form's BeforeUpdate event.  This event is the LAST event to run prior to the record being saved.  It ALWAYS runs when the record is being saved regardless of why Access is saving the record.  When you put code like this into incorrect events, there will always be situations where your code gets bypassed.

Form events are logical and not to be used randomly.  Each has a specific purpose.  It is important to learn what triggers an event so you know what type of processing to perform in it.

Also, you don't need the If statement since the BeforeUpdate event runs ONLY if the record is dirty.

Me.txtRevDate = Now()

is all you need, provided it is placed into the correct event.
which line is the error on?
if the destination field is text you may need to convert now to text e.g. CTEXT(Now())
John TsioumprisSoftware & Systems EngineerCommented:
Datachange is an event used in PivotTable view.
If you want to check for any change then
If me.dirty the me.dirty = false

Open in new window

SteveL13Author Commented:
Coachman99:  I do not know which line the error is on.  I set a breakpoint but nothing happens other than the error.  The destination field is general date.

John:  Your suggestion does not work at all.
COACHMAN99Connect With a Mentor Commented:
if you comment the Me.txtRevDate = Now() line and the error goes you know.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.