Microsoft Access VBA Macro Programming

(Tina Sui) #1
The API call is made, returning a value into the variable x. If the return value is zero, then
the user canceled the operation, but if there is a return value, then the selected color value can
be found in CSel.rgbresult.
By calling ShowColorDialog from anywhere within your form code, you can make the
Color dialog appear and allow the user to select a color.
Notice that the color is returned as an RGB value. You can use this for any color property
on the form, such as:

Me.Detail.BackColor = 47456

This will set the BackColor property to the choice that the user made in your dialog.

The Print Dialog


The Print dialog is remarkably easy to display and has the added advantage that you do not
need to write any code to do the printing!

DoCmd.RunCommand acCmdPrintSelection

This simple command will display the standard Print dialog and allow the user to select
what will be printed and choose a printer. It can be run from anywhere in your code.
Unfortunately, the RunCommand method cannot be used for all dialogs, which is why the
File Open, Save File As, and Color dialogs have been created using API calls. Also, using
API calls, you can obtain information on the user’s selection, which you cannot do from the
RunCommand method.

128 Microsoft Access 2010 VBA Macro Programming

Free download pdf