Access VBA Macro Programming

(Joao Candeias) #1

Chapter 10 Common Dialog Control


Chapter 10 Common Dialog Control


U


sing API calls (see Chapter 20 for more information), you can access the standard
Microsoft dialogs for opening files, saving files, printing, and selecting colors. All
the dialogs for these purposes that you see in standard Microsoft applications are
yours for the taking to use within your own programs.
By using particular API calls, you can choose what dialog to display and be able to set
various parameters to alter the appearance of the dialog to suit the purpose of your program.
Even better, you can then retrieve the parameters that the user has selected and have your
code act on them accordingly. For example, if the user selects a file to open, you can easily
find out the file and pathname, and write the code accordingly.
An important point is that these are only dialogs to provide a common interface to the
user. You must still write the code to handle the selections or events that the user chooses; it
does not happen automatically. For example, if you display the Save dialog, and the user
types a filename and presses OK, nothing will happen unless you have written the code to
collect the filename chosen and the code to save the data to that filename.
Microsoft provides an important helping hand here so you do not have to reinvent the
wheel to provide common user interface components. However, you still have to do some of
the work in selecting the options that will be available on the dialogs and interpreting what to
do with the user’s selection.
In all the following examples, you will need to create a form with a button to call the
various procedures. You do this by selecting Create in the Access menu and then clicking the
Form Design Icon in the Forms group of the ribbon. Click Design in the Access menu and
drag a command button from the Controls group of the ribbon onto your form. Dismiss the
wizard dialog by clicking Cancel. It is assumed in all the following examples that this button
object is called Command0.


123

Free download pdf