Create a message box programmatically

Microsoft Office Access 2003

procedure.

ShowUse a macro

  1. Create a macro.

    ShowHow?

    1. In the Database window, click Macros Button image under Objects.
    2. Click the New button on the Database window toolbar.
  2. In a blank action row, click MsgBox in the action list, and then set the action arguments.
  3. Click Save Button image to save the macro.
  4. To test the macro, click Run Button image on the toolbar.

ShowUse Visual Basic code

  1. Create a Visual Basic procedure.

    ShowHow?

    1. In the Database window, click Modules Button image under Objects, and then click New on the Database window toolbar.

    2. Declare the procedure by typing the Sub statement.
    3. Type a procedure name, immediately followed by any arguments in parentheses. For example, the following declaration for the ShowEvent Sub procedure specifies EventName as an argument:
      Sub ShowEvent(EventName As String)
      										
  2. Add an assignment statement to the procedure that assigns the value returned by the MsgBox function to a variable. The function returns different values depending on the button a user clicks in the message box. Your procedure can then perform different operations based on the value returned.

    For example, the following assignment statement runs the MsgBox function, displaying a message, and assigns the value returned by the function to the variable RetValue:

    RetValue = MsgBox("Continue?", vbOKCancel)
    						
  3. To test, run the procedure by clicking Run Sub/UserForm Button image on the toolbar, select the procedure in the Macros dialog box, and then click Run.