Question:
Access 2003 Message Box Question?
Jeff M
2007-10-04 10:27:42 UTC
Ok I've been playing around with the MsgBox function in my database, I would ultimately like to have a box popup, when the user is finished entering the data and clicks the save command button. Once this happens the popup box comes up asking if they are sure they want to save or they can cancel.

I've tried to put it on the onclick event of the command button and put the code as something along the lines of

MsgBox "Are you sure you want to save the record?", vbOkCancel,

and then I'm not really sure what other code I need to have, or the right event to place it at, because if they hit the ok button I want the record to save and move to a new record, if they hit cancel, I want it to go back to the form with everything as is and not saved. Please help, if this doesn't make sense let me know and I will see if I can explain it better.

When I tried this before, regardless if they hit ok or cancel it still saved the record.
Three answers:
2007-10-04 11:15:38 UTC
This was a good question, and I know how to do it in C#, VB.NEt, etc, but not VBA. So I found a great article on MSDN about it.

http://msdn2.microsoft.com/en-us/library/aa164019(office.10).aspx#odc_tentipsvba_topic2

Sounds like you need to declare a response item as an integer, then take an action based on the response entered (vbYes, vbNo). By the way - are you using the vbYesNoCancel? I would suggest using it instead of the vbOkCancel. Good luck, and let me know if this doesn't work...
BlueFeather
2007-10-04 11:42:31 UTC
Sounds similar to what I've been doing for years, except I usually don't prompt before saving. (I consider it a nuisance to the user)



I typically have a "Save" button on a form. When clicked, code behind the button saves data from the form to the appropriate table(s).



However, my forms (and form elements) are almost always unbound, so it requires a little more effort (i.e. coding) on my part to manage the forms -- but that is the fun part!



If you need details, email me and I will find some sample code to send you.



ยง
2007-10-04 11:10:38 UTC
You should put the code in the before update event and cancel the event if the result is cancel.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...