ACC97: Macro to VBA Uses Unexpected Syntax with Form References

ID: Q162074

The information in this article applies to:

SYMPTOMS

Advanced: Requires expert coding, interoperability, and multiuser skills.

When you use the "Convert Macros to Visual Basic" command to convert a macro that contains a reference to a user-defined item on a form or report to a Visual Basic for Applications event procedure, the code syntax that is created from the conversion will use the . (dot) operator instead of the ! (exclamation point) operator for any implicit referencing in the procedure.

CAUSE

The "Convert Macros to Visual Basic" command does not differentiate between implicit and explicit referencing when a macro is converted to a Visual Basic for Applications procedure.

RESOLUTION

In modules that are created from the "Convert macros to Visual Basic" command, both operators are acceptable.

MORE INFORMATION

In Microsoft Access, the ! (exclamation point) operator and the . (dot) operator are used as identifiers to indicate if a particular reference is implicit (!) or explicit (.). Implicit referencing usually means that you are referring to a user-defined item. Explicit referencing usually means you are referring to an item defined by Microsoft Access. However, when you use the "Convert Macros to Visual Basic" command, the distinction is not made for implicit and explicit form referencing.

For example, if the macro contains an entry in the condition column that reads as follows

   Condition             Action
   ------------------------------
   [PrintLabelsFor]=1    SetValue

   Action Arguments
   --------------------------------------
   Item:        [SelectCountry].[Enabled]
   Expression:  No

it will be converted to the following:

       With CodeContextObject

          If (.PrintLabelsFor = 1) Then

Note the . (dot) operator that precedes PrintLabelsFor. The ! (exclamation point) operator should be used instead of the . (dot) operator.

Steps to Reproduce Behavior

1. Open the sample database Northwind.mdb.

2. Click the Macros tab and select the Customer Labels Dialog macro.

3. On the Tools menu, point to Macro, and then click "Convert Macros to

   Visual Basic" on the menu that appears.

4. In the "Convert macro: Customer Labels Dialog" dialog box, make sure the
   "Add error handling to generated functions" and the "Include macro
   comments" check boxes are selected. Click Convert.

5. When the conversion process is finished, click OK to the "Conversion
   Finished!" message box.

6. Open the Converted Macro-Customer Labels Dialog module in Design view.

Note the syntax created for the implicit form references. The actual code created will contain the . (dot) operator instead of the ! (exclamation point) operator. The example below shows the code syntax for the With statement that should be created from the conversion:

    With CodeContextObject
     ' Attached to the Customer Labels Dialog form.
     ' Attached to the PrintLabelsFor option group.
     If (!PrintLabelsFor = 1) Then
     ' If user selects All Countries, do not enable the SelectCountry
     ' combo box.
         !SelectCountry.Enabled = False
     End If
     If (!PrintLabelsFor = 2) Then
     ' If user selected Specific Country, enable the SelectCountry
     ' combo box.
       !SelectCountry.Enabled = True
          ' Go to the SelectCountry
       DoCmd.GoToControl "SelectCountry"
  End If
  End With

REFERENCES

For more information about implicit and explicit form referencing, search the Help Index for "referencing, controls in expressions," and then "Use the ! and .(dot) operators in expressions" or ask the Microsoft Access 97 Office Assistant.

Additional query words:

Keywords          : kbprg
Version           : 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbprb

Last Reviewed: November 20, 1998