Microsoft Access - Using Intrinsic Constants In Parameters (Access 97/2000/2002)


When you create VBA procedures that accept parameters, you may wish that you could take advantage of the constants that are automatically available when working with common properties and methods. For example, when you enter:


  • DoCmd.Close

In a procedure and press [Spacebar], the IntelliSense feature automatically displays a dropdown list of the relevant object type constants. Now, let's say that you create a procedure like the following:


  • Sub DoStuff(strObjectName As String, intObjectType As Integer)
  • '...
  • Do stuff
  • '...
  • End Sub

You need to pass an object name and type to the procedure. Although the object type is an integer value, you can use an intrinsic constant to pass the appropriate values, such as with the statement


  • DoStuff "EmployeeForm", acForm

However, you must already know the appropriate constant, because the VBE won't provide the list of valid possibilities as the procedure is currently written. Fortunately, there's a way to take advantage of existing constant collections. To do so, declare the parameter using the appropriate class name. For example, change the procedure to the following:


  • Sub DoStuff(strObjectName As String, intObjectType As AcObjectType)
  • '...
  • Do stuff
  • '...
  • End Sub

When you subsequently call the procedure, the dropdown list of constants appears as soon as you add a comma after the name parameter.

Go back