Solved

Close form event - Type Mismatch

Posted on 2016-09-29
5
27 Views
Last Modified: 2016-09-29
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
0
Comment
Question by:SteveL13
5 Comments
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 41822012
which line is the error on?
if the destination field is text you may need to convert now to text e.g. CTEXT(Now())
0
 
LVL 13

Expert Comment

by:John Tsioumpris
ID: 41822022
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

0
 

Author Comment

by:SteveL13
ID: 41822043
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.
0
 
LVL 7

Assisted Solution

by:COACHMAN99
COACHMAN99 earned 250 total points
ID: 41822049
if you comment the Me.txtRevDate = Now() line and the error goes you know.
0
 
LVL 34

Accepted Solution

by:
PatHartman earned 250 total points
ID: 41822233
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.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now