My Message Box problem Part 2

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

Tony Williams

Thanks to Graham Seach I have my message box with Yes and No buttons. When
a user enters a new record they wanted a prompt that asks if they were sure
the record should be saved. This is the code I have in the Before Update
property of my form
If Me.NewRecord Then
Cancel = (vbNo = MsgBox("Are you sure you want to save this new record?",
36))
End If

However what I would like to do is this; if the user clicks on Yes I want
this to happen
If Me.NewRecord Then
Populate_URN
End If
DoCmd.Requery "Docnumtxt"
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
If the user Clicks on No I want this to happen
Me.Undo
in other words I want the form to be cleared and the record not saved.

How do I trap the yes and No answers?
TIA
Tony Williams
 
Tony,

If vbYes = MsgBox("Are you sure you want to save this new record?",
vbYesNo) Then
If Me.NewRecord Then Populate_URN

Me.Docnumtxt.Requery
DoCmd.RunCommand acCmdSaveRecord
Else
Me.Undo
End If

However, Me.Undo only undoes changes made to the form since the last save.
If you want to completely clear the form, you'll have to do it in code.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Thanks again Graham!
Tony
Graham R Seach said:
Tony,

If vbYes = MsgBox("Are you sure you want to save this new record?",
vbYesNo) Then
If Me.NewRecord Then Populate_URN

Me.Docnumtxt.Requery
DoCmd.RunCommand acCmdSaveRecord
Else
Me.Undo
End If

However, Me.Undo only undoes changes made to the form since the last save.
If you want to completely clear the form, you'll have to do it in code.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Graham this seems to save the record when I click No and close the form it
doesn't Undo
as it should?
Any ideas?
Tony
 
Also Graham if I update a record and click on my Save Command button it
deletes the data I have added?????
Tony
 
Tony,

The only thing I missed (sorry) was the Cancel=True line.

If vbYes = MsgBox("Are you sure you want to save this new record?",
vbYesNo) Then
If Me.NewRecord Then Populate_URN

Me.Docnumtxt.Requery
DoCmd.RunCommand acCmdSaveRecord
Else
Me.Undo
Cancel = True
End If

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Back
Top