Solved

Close form event - Type Mismatch

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

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 36

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

740 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