Modal versus Modeless Forms

A modal form is any form that prevents your macro from continuing, and restricts interaction with the parent application, until the form is closed. A modeless (or nonmodal) form does not have these restrictions, allowing for other macro code to be executed as well as interaction with the parent application while the form is displayed.

There are two ways VBA allows you to control the modal state of a form. The first is via the form’s ShowModal property setting. A value of True will display the form as modal while a value of False will display the form as modeless. The other way to set the modal state is via your macro code. The form’s Show method takes an optional argument (either vbModal or vbModeless) that will override the form’s ShowModal property setting. The two methods are illustrated below.

Setting the Modal state in the form properties

Setting the Modal state in your macro code

‘Example for showing a form either as Modal or Modeless
Public Sub MyMacro()
    'Typical method to show a form
    'Modal state uses the form’s ShowModal property
     UserForm1.Show

    'The following two methods override the form’s
    'ShowModal property

    'Use this line to show a form as modal
     UserForm1.Show vbModal

    'Use this line to show a form as modeless
     UserForm1.Show vbModeless
End Sub

EnvisionCAD

Since 1996, EnvisionCAD has been a nationally recognized leader in the configuration, customization, implementation, training & support for CAD software solutions. Our individualized approach has benefited private engineering firms and government agencies alike. Basic or advanced, we can help you get the most from your CAD technology.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *