Access VBA Macro Programming

(Joao Candeias) #1

Initially, this code sets up a variablewto represent aTableDefobject. This represents the
current table definition being cycled through. The code then cycles through theTableDefs
collection using a For Each..Next loop. The code takes each table definition in turn, gets the
name property, and displays it in a message box onscreen, as shown in Figure 14-1. Your
code sheet should look like Figure 14-2.
TheDimstatement is short forDimension; it creates a space in memory for a variable. In
this case, it creates space for a standard table definition. You can run this routine without the
Dimline, but it does have advantages because it will give you automatic assistance with
properties and methods. When you type theDim w Asstatement, a list box appears when
you get to theTableDefpart. When you type inMsgBox w.name, a list box will appear after
you typewthat shows all the properties and methods you can use. This is extremely helpful
when programming because it allows you to immediately see what your options are for the
next piece of code.
The structure of the object models is extremely complicated, and you should not expect
to remember every object, collection, property, and method within it. If you do not use the
automatic list boxes that appear as you type object code in, you will be constantly referring to


Chapter 14: The Access Object Models 183


Figure 14-1 Message box displaying names of Table Definitions

Free download pdf