Solved

Close form event - Type Mismatch

Posted on 2016-09-29
5
34 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

910 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

21 Experts available now in Live!

Get 1:1 Help Now