ACC: Syntax for Using Object Variables in Expressions

Last reviewed: May 21, 1997
Article ID: Q133228
The information in this article applies to:
  • Microsoft Access versions 2.0, 7.0, 97

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 SynRef
Version : 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 21, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.