Microsoft Office Tutorials and References
In Depth Information
Writing Your Own VBA Procedures
What’s with the simplified syntax?
Many optional arguments available in VBA
statements represent advanced concepts that are
difficult to describe out of context. This topic often
shows a simplified version of the syntax for a given
statement, focusing on those arguments that you
need to use or are likely to want to use. When you
compare the simplified syntax shown in this topic
with the actual syntax shown in the Visual Basic
Editor help pages, you may see differences. Don’t
be alarmed. We haven’t made a mistake.
Using the simplified syntax in this topic allows
you to discover VBA programming in a manner
that focuses on the most basic — and most
important — stuff first. You can work your way
to the more advanced — and mostly optional —
stuff as needed. The simplified syntax may well
be all you ever need to use when writing your
The simplified syntax for the Function statement (with some of the
optional stuff removed) is similar:
Function name [( arglist )] As type
In both cases, arglist is optional, as indicated by the square brackets. But
even the optional arglist has a syntax, the simplified version of which is
name [As type ]
name is a name you make up. You can list multiple arguments by separating
their names with commas.
The type component specifies the data type of the data. Like Access tables,
VBA supports multiple data types. These data types are similar (but not
identical) to data types defined for fields in the structure of a table. The
String data type in VBA, for example, is similar to the Text data type in an
Access table, in that both contain text.
Table 2-1 lists the VBA data types that work best with Access. The Storage Size
column shows how many bytes each data type assumes. The Declaration
Character column shows an optional character used at the end of a name
to specify a data type. (The name PersonName$, for example, defines
PersonName as containing a string.) In the real world, though, you really
needn’t concern yourself too much with those columns. The first two
columns in the table provide the information you really need to know.