I have code that I’ve never had a problem with in Access97 or Access2000. But in Access2003 generates an error every time in a particular circumstance. I have a SAVE button on a form, and the code for the button and the forms BeforeUpdate looks something like t his:
Private Sub cmdSave_Click()
If me.dirty then runcommand acCmdSaveRecord
If me.dirty then Exit Sub
‘ other code
End Sub
Private sub Form_BeforeUpate (Cancel as integer)
if isnull(txtCustomerName) then
MsgBox “Fix customer name”
Cancel=True
Exit Sub
End if
Exit Sub
In my real code, I have error handling in both events. If this is a new record, and if there is a null entry in txtCustomerName, this generates an error# 3021 “No Current Record” error in the error handler in my cmdSave_Click code. If it is an existing record, there is no such error raised.
Curiously, this error isn’t raised if the BeforeUpdate event code is triggered from such action as trying to move to a subform so that Access tries to save the record.
I’ve gotten around this by putting this line of code in error handler:
If err.number =3021 then Resume ExitHere
But I use this code technique alot, in every button that may or should force the record to be saved. Going into all of them on every form will be a pain.
Any ideas why this is happening?