Yes/No Question box in a form?

Joined
Dec 17, 2013
Messages
37
Hi,

I have got a data input form in access, and i would like a yes/no message box to appear when the "complete order" command button is pressed. The command button is linked to a macro which runs a set of queries in the completion process. I have tried writing VBA code to do this in access, however i am not too familiar with writing vba in access and cannot understand a problem that i encountered. I transferred the original macro to vba code and then added in my own message box macro, however when the button is pressed, the message box code seems to be ignored and the macro just runs anyway. However when trying the message box code by itself, it runs. Can anybody suggest anything that could help me out on this?

This is the vba that i used, if it would be any help

Code:
 Const cstrPrompt As String = _
        "Are you sure you want to save this record? Yes/No"
    If MsgBox(cstrPrompt, vbQuestion + vbYesNo) = vbNo Then
        Cancel = True
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "complete", acViewNormal, acEdit
    DoCmd.OpenQuery "delte_orders", acViewNormal, acEdit
    DoCmd.Close acForm, "Orders"
    DoCmd.SetWarnings True

Thanks in advance,

Heyyouyesyounonotyouyou
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
An IF statement should have two branches, one to do something if true, the other if false. I see only one branch in your posted code, and it appears to do everything you don't want it to do.

Is this code for an event? Which one?
 
Upvote 0
What it should be doing is bringing up a question box when a the save button is clicked (in a form). The question box should carry on with the process if "Yes" is selected, and when "No" is selected it should cancel the process. I'm not sure if my code needs tweaking or I need to go about this in a completely different way.

Cheers
 
Upvote 0
Code:
Const cstrPrompt As String = _
        "Are you sure you want to save this record? Yes/No"
    If MsgBox(cstrPrompt, vbQuestion + vbYesNo) = vbNo Then
        Cancel = True
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "complete", acViewNormal, acEdit
    DoCmd.OpenQuery "delte_orders", acViewNormal, acEdit
    DoCmd.Close acForm, "Orders"
    DoCmd.SetWarnings True

You have a "Cancel = True" in this code, which leads me to wonder what you are canceling. If it is a Form Before Save event, then maybe:

Code:
Dim strPrompt As String
        
    strPrompt = "Are you sure you want to save this record? Yes/No"
    If MsgBox(cstrPrompt, vbQuestion + vbYesNo) <> vbYes Then
        Cancel = True
    Else
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "complete", acViewNormal, acEdit
        DoCmd.OpenQuery "delte_orders", acViewNormal, acEdit
        DoCmd.Close acForm, "Orders"
        DoCmd.SetWarnings True
    End If


See how you do one thing or another, based on the response? IF ... ELSE ...
 
Upvote 0

Forum statistics

Threads
1,212,938
Messages
6,110,788
Members
448,297
Latest member
carmadgar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top