Save option on close

jax

Registered User.
Local time
Today, 11:53
Joined
Mar 4, 2002
Messages
61
I have the following code on a close command button on a form:-

MsgBox "Do you want to save this information?", vbYesNo
If vbYes Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveNo, , acMenuVer70
DoCmd.Close
End If

The message box displayed gives the user the choice of saving any data added. My problem is that it doesnt matter which option the user chooses - Access saves the data! How do I get the NO option to work? Help??


[This message has been edited by jax (edited 04-29-2002).]

[This message has been edited by jax (edited 04-29-2002).]
 
Actually, believe it or not, Access actually saves the record automatically if you move on to another record or use Add New.

If you want to use your code as listed, you can modify your code (see below) and it should fix your problem.

If MsgBox ("Do you want to save this information?", vbYesNo)= vbYes Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close
Else
Me.Undo
DoCmd.Close
End If


BL
hth


[This message has been edited by boblarson (edited 04-29-2002).]
 
thanks I will try your code. I know Access saves automatically but I dont want it to, I want to give the user the option.
 
I tried the code, it still saves the record whether yes or no is chosen! any further help would be greatly appreciated.
 
the way I got around this was to create a delete query with the criteria being the primary key field on the form. then on the close button if they don't want to save the record it will run the delete query and delete the current record or else it will just close the form
 
I got the code below working:-

If MsgBox("Do you want to save this information?", vbYesNo) = vbYes Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close
Else
DoCmd.RunCommand acCmdUndo
DoCmd.Close
End If
End Sub

The only problem I am having now is that it wont close the form if its blank and the user choses NO to the save options. I get an error message about cant undo, any ideas how I get around this problem.
 
Try a check for Me.Dirty = False
 

Users who are viewing this thread

Back
Top Bottom