This article was previously published under Q209511
This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).
Moderate: Requires basic macro, coding, and interoperability skills.
↑ Back to the top
In a Microsoft Access macro, a SendKeys action must precede a RunCommand action when you need to send keystrokes to a dialog box. For example,
when a RunCommand action opens the Print dialog box to change a printing parameter, the SendKeys keystrokes remain in the buffer. If the SendKeys action follows the RunCommand action, the keystrokes will not run.
↑ Back to the top
Because opening a dialog box suspends a macro, you must carry out the SendKeys action before the dialog box opens. The following example demonstrates how to open the
Print dialog box.
- Open an Access 2000 database.
- Create a new macro as follows:
Action: SendKeys
Keystrokes: %g1%t5{ENTER}
Wait: No
Action: RunCommand
Command: Print
NOTE: If you manually open the Print dialog box, you will see that the keystrokes are to first select the Page Print Range option (that is, %g or ALT+G), insert a 1 into the From box, and then to insert a 5 in the To box (that is, %t or ALT+T). - Close and save the macro as mcrPrint, and double-click the macro to carry it out. The macro carries out its actions, and then opens the dialog box to print out the properties, actions and arguments, and user/group permissions of the mcrPrint macro.
↑ Back to the top
For more information about how SendKeys works, click Microsoft Access Help on the
Help menu, type SendKeys Action in the Office Assistant or
the Answer Wizard, and then click Search to view the topics
returned.
For more information about SendKeys syntax, click Microsoft Visual Basic Help on the
Help menu, type SendKeys Statement in the Office Assistant or
the Answer Wizard, and then click Search to view the topics
returned.
↑ Back to the top