Access VBA Macro Programming

(Joao Candeias) #1

This will return the value of MyField for the last record in the table MyTable. You can use
an optional criterion as follows:


MsgBox DLast("MyField", "MyTable", "MyValue<=10")


DLookup


TheDLookupmethod allows you to extract a field value found in a table using a criteria
string. An example is:


MsgBox DLookup("MyField", "MyTable", "MyValue=5")


This will return the value of MyField in the table MyTable where MyValue is equal to 5.
The criteria parameter is optional, but if this is not entered, the method will work in the same
way asDFirst.
This will only return one value. If there are several records within the criteria, only the
value for the first one will be returned.


DMax


The methodDMaxallows you to locate the maximum field value in the first record found in
a table. An example is:


MsgBox DMax("MyField", "MyTable")


This will return the maximum value of MyField in the table MyTable. MyField can be any
data type. You can use an optional criterion as follows:


MsgBox DMax("MyField", "MyTable", "MyValue> 6 ")


DMin


The methodDMinallows you to locate the minimum field value in the first record found in a
table. An example is:


MsgBox DMin("MyField", "MyTable")


This will return the minimum value of MyField in the table MyTable. MyField can be any
data type. You can use an optional criterion as follows:


MsgBox DMin("MyField", "MyTable", "MyValue> 6 ")


DoCmd


DoCmdis a very important object for Access VBA programmers as it emulates all the macro
commands available in the macro window. It is discussed in detail in Chapter 16.


DSum


The methodDSumlets you sum field values for a given field within a table. An example is:


MsgBox DSum("MyField", "MyTable")


Chapter 15: The Main Objects 197

Free download pdf