Share via

Access Form Message Box

Anonymous
2010-08-13T08:55:48+00:00

I wish to create a message box with Yes, No options which I have managed to do by entering the following in the On Click data properties =msgbox("are you sure you want to continue?,4+48).

However I want to be able to run a query if you click on Yes and Exit if you click on No. I am not very experienced with VB and have therefore become stumped by how to do this.

Is anyone able to help? Thanks

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-08-13T09:44:02+00:00

Hi shoeic

Create an Event Procedure for the On Click event of the control.

I used a button called cmdButtonName

This is the code you need for the On Click event.

Private Sub cmdButtonName_Click()

On Error GoTo Err_cmdButtonName_Click

    If MsgBox("Are you sure you want to continue?", vbYesNo + vbQuestion, "Confirmation Required") = vbYes Then

        DoCmd.RunMacro "YuorMacroName"

    End If

Exit_cmdButtonName_Click:

    Exit Sub

Err_cmdButtonName_Click:

    MsgBox Err.Description

    Resume Exit_cmdButtonName_Click

End Sub

Hope this helps


Bob Fitz

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-08-13T11:30:13+00:00

    Fantastic, that works! Thanks very much for your help

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-08-13T09:47:14+00:00

    If MsgBox("Are you sure you want to conitu?4+48", vbQuestion + vbYesNo) = vbYes Then

    DoCmd.OpenQuery "Query Name", acViewNormal, acEdit

    Else

    DoCmd.Close

    'insert DoCmd.Quit if you really want to quit the application

    End If

    Was this answer helpful?

    0 comments No comments