Yes/No message box macro help

tessw

New member
Local time
Today, 12:01
Joined
Mar 13, 2013
Messages
4
Hi,
I have no knowledge on how to use vba. But I basically want to have a save button on my form from which a warning message will appear asking the user "Are you sure?" and then I want a Yes and No option for the user to select. Obviously from that if the user selects yes then the record will be saved, and if No then nothing happens.

Any help will be really appreciated, I have searched around online for some help but what I found was a bit difficult to understand.

This is for my sixth form project and I need to make my database a bit more complex so using this would be really useful

Thanks,
Tess :rolleyes:
 
At what point do you want your message box? When closing the form?
 
Add similar to the following to the button's click event:
Code:
Private Sub Command0_Click()
If MsgBox("Save changes?", vbYesNo, "Title Here") = vbNo Then
    Exit Sub
Else
    'Your stuff here
End If
 
Add similar to the following to the button's click event:
Code:
Private Sub Command0_Click()
If MsgBox("Save changes?", vbYesNo, "Title Here") = vbNo Then
    Exit Sub
Else
    'Your stuff here
End If
Sorry if i'm being a pain where do i need to add this to?
 
In design view... right-click on the button, select "Build Event" then "Code Builder". This will bring up the code module of the form and should already be in the click event (Private sub Commnd_Click) Place the code between the the private sub line and the end sub line.
 
In design view... right-click on the button, select "Build Event" then "Code Builder". This will bring up the code module of the form and should already be in the click event (Private sub Commnd_Click) Place the code between the the private sub line and the end sub line.

Thank you soooo so much!!! Literally a life saver! :D:D
 
I'm wondering why you need a Save button. Unlike Excel or Word, Access saves the changes to your data automatically as soon as you leave the current record or close the form, so a Save button would serve no such purpose. If you've started editing a record and then change your mind, just hit Esc. Otherwise, the Save method (DoCmd.Save) can be used to save an object (form, report, query, etc), so unless your actually trying to save changes to the form itself, what is the Save button for?
 

Users who are viewing this thread

Back
Top Bottom