Checking for a record change

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
 
V

Van T. Dinh

Suggest you check Access / Access VB Help on the Form_BeforeUpdate in stead
of your current code.
 
T

Tony Williams

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
 
V

Van T. Dinh

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!
 
T

Tony Williams

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

If statement 4
message box problem 4
Error 2237 8
checking for existing record 3
Cmd Button Does not work on first click 2
Auto date changes on continues forms 6
close without saving - HELP 2
Run-time error 2115 3

Top