Show or hide warning messages programmatically

You can temporarily disable the modal (modal: A window or dialog box that requires the user to take some action before the focus can switch to another form or dialog box. Dialog boxes and messages are usually modal.) warning messages displayed by Microsoft Access while a macro or Microsoft Visual Basic procedure is running, and enable them again by carrying out the SetWarnings action in the macro or procedure.

ShowUse a macro

  1. To open an existing macro, click Macros Button image under Objects, select the macro, and then click the Design button on the Database window toolbar.
  2. In the place in the macro where you want to stop or resume the display of modal warning messages, add the SetWarnings action.

ShowHow?

  1. In the Macro window, click the first empty row in the Action column. If you want to insert an action between two action rows, click the selector for the action row just below the row where you want to insert the new action, and then click Insert Row Button image on the toolbar.
  2. In the Action column, click the arrow to display the action list.
  3. Click the action you want to use.
  4. In the lower part of the window, specify arguments for the action, if any are required. For action arguments whose settings are a database object name, you can set the argument by dragging the object from the Database window to the action's Object Name argument box.
  5. Type a comment for the action. Comments are optional.
  1. To temporarily stop the display of warning messages, set the Warnings On argument to No. To resume displaying them, set the Warnings On argument to Yes.
  2. Click Save Button image to save the macro.
  3. To test, click Run Button image on the toolbar.

If the Warnings On argument was set to No, the display of warning messages automatically resumes when the macro stops running.

ShowUse Visual Basic code

  1. Open a Function or Sub procedure in the Code window.
  2. In the place in the procedure where you want to stop or resume the display of modal warning messages, use the SetWarnings method to carry out the SetWarnings action.

ShowHow?

Microsoft Access defines a special object, DoCmd, that you use to carry out macro actions in Microsoft Visual Basic procedures. You carry out an action by adding a method of the DoCmd object to your procedure.

  • In the procedure, add the DoCmd method that corresponds to the action by using the following syntax:

DoCmd.method [arguments]

Method is the name of a method. Arguments are the method arguments, if there are any.

For example:

DoCmd.SetWarnings False
                        
  1. To temporarily stop the display of warning messages, set the warningson argument to False. To resume displaying them, set the warningson argument to True.
  2. To test, run the procedure by opening the form in Form view and performing the event that triggers the procedure

If the the warningson argument was set to False, the display of warning messages automatically resumes when the code stops running.

 
 
Applies to:
Access 2003