Prev | Current Page 1603 | Next

Michael R. Groh, Joseph C. Stockman, Gavin Powell, and Cary N. Prague

"Access 2007 Bible"


Using control variables
When referencing controls on a form in code, there are some very slow ways and some very fast
ways to use references to form objects. The slowest possible way is to reference each control explicitly.
This requires Access to search for the form name sequentially, starting with the first form name
in the database and continuing until it finds the form name in the forms list (msysObjects
table). If the form name starts with a z, this can take a long time if the database contains many
forms. For example:
Forms![frmSales]![SaleDate] = something
Forms![frmSales]![InvoiceDate] = something
Forms![frmSales]![SalespersonID] = something
TIP
846
Professional Database Development Part IV
If the code is in a class module behind the frmSales form, you can use the Me reference. The Me
reference refers to the open object (forms or reports) and substitutes for Forms![formname].
This is a much faster method because it can go right to the form name. For example:
Me![SaleDate] = something
Me![InvoiceDate] = something
Me![SalespersonID] = something
If your code is not stored behind the form but is in a module procedure, you can use a control
variable like the following:
Dim frm as Form
set frm = Forms![frmSales]
frm![SaleDate] = something
frm![InvoiceDate] = something
frm![SalespersonID] = something
This way, the form name is looked up only once.


Pages:
1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615
gry dla dziewczyn Obyczajowe, romantyczne Tworzenie stron Katowice Akcesoria komputerowe Fantastyczne, fantasy