Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message Box

Status
Not open for further replies.

Muzzy

Programmer
Dec 14, 2001
68
GB
I have the following code:

MsgBox "Are You Sure You Want To Submit The Quarterly Figures?", vbOKCancel, "Are You Sure?"

After the above code if the user clicks yes, I need to say run the rest of the code below. However, if the cancel button is clicked I need to skip this code and just stop the operation.

DoCmd.Hourglass True
stDocName = "qryAppendFinExpCurr"
DoCmd.OPENFORM "frmCreateSnapshot", acNormal, , , acFormPropertySettings, acHidden
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.Close acForm, "frmCreateSnapshot", acSaveNo
MsgBox "Quarterly Update complete", vbInformation, "Update Complete"
DoCmd.Hourglass False

Any ideas?
 
Muzzy -

Make sure to assign a variable to the answer of the Msgbox.

ans = MsgBox "Are You Sure You Want To Submit The Quarterly Figures?", vbOKCancel, "Are You Sure?"
If ans = vbCancel Then
Exit Sub
Else
DoCmd.Hourglass True
stDocName = "qryAppendFinExpCurr"
DoCmd.OPENFORM "frmCreateSnapshot", acNormal, , , acFormPropertySettings, acHidden
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.Close acForm, "frmCreateSnapshot", acSaveNo
MsgBox "Quarterly Update complete", vbInformation, "Update Complete"
DoCmd.Hourglass False
Endif

Hope this helps!
 
Personaly I prafer to use fewer variables... I also don't like exit sub's... this is how I'd run it...


if MsgBox ("Are You Sure You Want To Submit The Quarterly Figures?", vbOKCancel, "Are You Sure?") = VBOK then
DoCmd.Hourglass True
stDocName = "qryAppendFinExpCurr"
DoCmd.OPENFORM "frmCreateSnapshot", acNormal, , , acFormPropertySettings, acHidden
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.Close acForm, "frmCreateSnapshot", acSaveNo
MsgBox "Quarterly Update complete", vbInformation, "Update Complete"
DoCmd.Hourglass False
end if


I'm not saying KathyD's solution isn't good or any thing, I think it's very good and well done... I just prafer to use fewer lines of code when possable...

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Thanks, but........

Didn't work, what do I declare the variable as, where and I get the error 'Syntax Error' Any advice

Cheers

Muzzy
 
if using KathyD's code... you need a
dim ans
at the top of the procedure...

mine shouldn't need any variables that you don't have there...

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Thanks all, I have got it to work now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top