Forms in VBA
 
 
 

Forms are the basic building blocks through which you create your own custom dialog boxes for your application. Through custom forms you can provide information to users, get information from users, or have your users control activity in the application.

Forms are like an artist's canvas—they start out blank. To fill your canvas, you need a palette. In this case, your palette is the control toolbox. You, as the artist, place selected controls from the toolbox onto the form. You can add as many controls as you like. At any time you can adjust size and properties of the controls and even the form itself. Finally, you add the functionality (code) to the controls that brings your form to life.

Although Visual Basic 6 supports different types of forms, VBA supports only the UserForm. This means some forms have been created and exported in Visual Basic 6 that cannot be imported into VBA.

UserForms—or forms, as they are called in this guide—can be modal or modeless. The ShowModal property of a form determines whether it is modal or modeless. Modal forms displayed in your running application must be closed before users can perform any other action in the application. For more information about working with modal forms, see Modal Forms .

To create a new form in your project

  1. Open the Project window of the VBA IDE and select the project you want to add the form to.
  2. From the Insert menu, choose UserForm.

    A blank form is created and added to your project.

To create a modeless form in your project

  1. Open the Project window of the VBA IDE and select the project you want to add the form to.
  2. From the Insert menu, choose UserForm, and change the ShowModal property to False.
  3. Add the AcFocusCtrl (AcFocusCtrl.dll) to the Toolbox, and drag the control onto the form.

    The AcFocusCtrl keeps the focus on the form during user interaction.