My Message Box problem Part 2

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
 
G

Graham R Seach

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
 
T

Tony Williams

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
 
T

Tony Williams

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
 
T

Tony Williams

Also Graham if I update a record and click on my Save Command button it
deletes the data I have added?????
Tony
 
G

Graham R Seach

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
 

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

Top