?
Solved

Close form event - Type Mismatch

Posted on 2016-09-29
5
Medium Priority
?
60 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 18

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 1000 total points
ID: 41822049
if you comment the Me.txtRevDate = Now() line and the error goes you know.
0
 
LVL 38

Accepted Solution

by:
PatHartman earned 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

762 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