PDA

View Full Version : Can I create message boxes on a yes/no drop down menu with a macro?



wedd
10-04-2010, 03:25 AM
Hi, Is it possible to create a macro pop-up message box on a yes/no combo drop down selection menu on ms access 2007? I've created a form titled Admin staff and a label text box entitled "Is this a tentative booking?" - when the user selects yes a pop message will be displayed and when the user selects no, again a message box will be displayed with a different message...if so, how can this be done? I've been using code in ms access 2003 which works...but when I implement the code in 2007 I receive error messages...I'm a beginner with vba in access, so if you have sample code or know of a great website that has similar examples to do this would be much appreciated - as It would be a great learning curve for me...

Thanks for your clever suggestions....:thumb

nepotist
10-04-2010, 05:51 AM
This code assumes that the name of the DropDown box is "Combo1".

MsgAnswer variable in the code reads the "Yes","No" or "Cancel" option selected by the user and then performs the action accordingly.

Private Sub Combo1_AfterUpdate()

Dim MsgAnswer As Integer

On Error GoTo Error_Handling

If Combo1.Value = "Yes" Then
MsgAnswer = MsgBox("Is this a tentative booking?", vbYesNoCancel)
If MsgAnswer = vbYes Then
'Add code to open the form
ElseIf MsgAnswer = vbNo Then
'Add code for selecting No
Else
'Cancel the operation
End If
Else
'Use the above format to code for other situations
End If

Exit Sub
Error_Handling:
MsgBox Err.Description, vbCritical

End Sub

Imdabaum
10-04-2010, 06:37 AM
Ultimately the answer is NO. You cannot create a yes/no msgbox in a macro. You can create a function in vba that shows the msgbox, and then in the Macro conditions you can call that function. The function must be compared to something resulting in a boolean though.

Unless you built your own custom form that mimicked the yes/no msgbox. In which case you could call OpenForm "[formName]". But then then you're still stuck writing the vba to perform your operation based on the selection.