ACC: Syntax for Using Object Variables in Expressions

ID: Q133228


The information in this article applies to:


SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

When you create expressions in Microsoft Access using Visual Basic for Applications or Access Basic, you can use variables to refer to objects, such as controls, forms, reports, and recordsets. However, when you reference object variables, you cannot use the exclamation point (!) as the identifier operator. Instead, you use parentheses, as in the following example:


   Forms("MyForm")(VarX) = "Any Value" 


MORE INFORMATION

In an expression, the standard syntax for referring to objects is to use an exclamation point (!) as an identifier, as in the following example:


   [Forms]![MyForm]![MyFieldName]= "Any Value" 

However, if the object is a variable, the exclamation point identifier is incorrect. You must use parentheses as the identifier, as in the following example:

   Dim x As String
   x = "MyFieldName"
   forms("MyForm")(x) = "Any Value" 


REFERENCES

For more information about identifiers in expressions, search the Help Index for "identifiers," or ask the Microsoft Access 97 Office Assistant.


Keywords          : kbusage 
Version           : 2.0 7.0 97
Platform          : WINDOWS 
Issue type        : kbinfo 

Last Reviewed: April 27, 1999