Checking for a record change

  • Thread starter Thread starter Tony Williams
  • Start date Start date
T

Tony Williams

I have a form with a command button that the user clicks to close the form.
The code behind the button checks if the record is a new one and a message
appears. I want to also check whether or not an existing record has been
changed and if so a different message appears and if the user has viewed the
record and made no change then no message appears. here is my code, how can
I change it to get the three options?
TIA
Tony Williams
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click

If Me.NewRecord Then
If vbYes = MsgBox("Do you want to save this new record?", 36, "Enter New
Record") Then
DoCmd.Requery "Docnumtxt"
DoCmd.RunCommand acCmdSaveRecord
Else
Me.Undo
Cancel = True
End If
Else
If Me.NewRecord = False Then
If vbYes = MsgBox("Do you want to save any changes you have made to this
record?", 36, "Save Changes") Then
DoCmd.RunCommand acCmdSaveRecord
Else
Me.Undo
End If
End If
End If
DoCmd.Close

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
 
Suggest you check Access / Access VB Help on the Form_BeforeUpdate in stead
of your current code.
 
Thanks Van I did look at using the BeforeuUpdate property but can't figure
out how to code the criteria because I want to check whether any control has
been changed on the form and if so ask the question "Do you want to save the
changes" My present code only checks for new records.
Am I missing something I am a bit of a newbie here.
Thanks again
Tony
 
The user must have changed something, i.e. (the Form's) Dirty = True for the
Form_BeforeUpdate Event to fire.

Thus, if the code in the BeforeUpdate Event is activated, you *already* knew
that the user must have changed some value(s) on the Form!
 
Thanks Van I think I'm beginning to understand know. I'll work on my code
during the day and come back to you tomorrow pm if I may with any other
problems that may arise on this thread.
Thanks again for your patience, I appreciate as a newbie it is sometimes
frustrating when we don't grasp the simplest things sometimes but I'll get
there. My 60 year old brain however doesn't work like it used to
Tony
 
Back
Top