BeforeUpdate expression produced error

  • Thread starter Thread starter jbiggs via AccessMonster.com
  • Start date Start date
J

jbiggs via AccessMonster.com

The expression Before Update you entered as the event property setting
produced the following error: The Save action was canceled.

*The expression may not result in the name of a macro, the name of a user-
defined function, or [Event Procedure].
*There may have been an error evaluating the function, event or macro.

Here is the code:

Private Sub lead_status_BeforeUpdate(Cancel As Integer)
Dim lastupdate As Date

lastupdate = Format(Nz(DMax("[note date]", "Notes", "[ID] =" & Me.ID),
"01/01/1900"), "mm/dd/yyyy")
'MsgBox "lastupdate =" & lastupdate & "ID =" & Me.ID
If lastupdate < date Then
MsgBox "You must update client's notes before changing status",
vbOKOnly, "Client notes not updated!"
Me.lead_status.Undo
Cancel = True
Else
DoCmd.Save
End If

End Sub
 
Format returns a string that you're trying to assign to a Date variable.

Try:

lastupdate = Nz(DMax("[note date]", "Notes", "[ID] =" & Me.ID),#01/01/1900#)

As well, it's possible that you're using "date" somewhere else in your
application (a control on your form, a variable, a function, a field in a
table, etc.). I say this because the VBA editor hasn't corrected your use of
date to upper case.

Try:

If lastupdate < VBA.Date() Then
 
Back
Top