Access VBA Macro Programming

(Joao Candeias) #1
This will display the name of each report loaded, but notice that it does not include reports
that are not loaded.
You can address controls on a report by using theControlscollection:

MsgBox Forms("MyForm").Controls("label 0 ").Caption

This will display the caption of the control called label0. You can also use this to change
the caption of the label control.

Screen
TheScreenobject provides properties for the screen of the application. You can use it to find
out what the active form or report is:

MsgBox Screen.ActiveReport.Name

You can also use it to change the MousePointer icon. This code changes the MousePointer
icon to an hourglass or busy icon:

Screen.MousePointer = 11

This code changes it back to the default:

Screen.MousePointer = 0

You could use Docmd.Hourglass to do this, but you can use a range of values here for
different icons.

SysCmd
One of the most useful functions of theSysCmdobject is to display a progress bar or meter
similar to the one you see when a query is running. It is very simple to do. First, you initialize
the meter:

SysCmd acSysCmdInitMeter, "Making Progress...", 100

This statement provides a label to describe the progress bar and sets an upper limit of 100
for the value. This can be set to any value.
Next, you create a statement to update the meter:

SysCmd acSysCmdUpdateMeter, 10

This gives a value of 10 to show how far the meter has moved. In this case, the upper limit
is 100, so this will fill in 10 percent of the progress bar.
Finally, when your process has finished, you need to remove the meter:

SysCmd acSysCmdRemoveMeter

This is very useful when you have a long process running that may embody several large
queries. You can provide the user with an indication of how far the process has run instead of
them seeing the progress bar for each individual query.

200 Microsoft Access 2010 VBA Macro Programming

Free download pdf