home *** CD-ROM | disk | FTP | other *** search
/ Computer Based Training: …, Windows 95 & NT Basics / a1454501.iso / mo97a03 / AA03.TXT < prev    next >
Encoding:
Text File  |  1997-05-16  |  11.1 KB  |  242 lines

  1. A @Rmacro@r is a set of one or more actions that automates a sequence of operations.
  2. |
  3. You can create Access 97 macros that automate the response of your database to certain events.
  4. |
  5. You can also define condition checking within a macro, so that different actions are performed depending on specific values.
  6. |
  7. Access provides various types of macro actions that can help you to automate tasks in your database.
  8. |
  9. For example, you can use macros to
  10.  
  11. ò open (or close) tables, queries, forms,
  12.   or reports in any available view
  13. |
  14. ò execute a select or action query
  15. |
  16. ò move, size, minimize, maximize, or
  17.   restore any window within the Access
  18.   workspace
  19. |
  20. Other functions of macros include
  21.  
  22. ò executing commands on any Access menus
  23. |
  24. ò displaying warning or information messages
  25. |
  26. ò sending data from a table, query, form, or
  27.   report to an output file, and then opening
  28.   that file in the appropriate application
  29. |
  30. With 49 macro actions to choose from in Access 97, the possibilities for macros are extensive.
  31. |
  32. Suppose you have a database called Product Info, in which you would like to keep a copy of the current database's Sales table.
  33. |
  34. You could create a simple macro that copies the table to the Product Info database.
  35. |
  36. Then, whenever you update the Sales table in the current database, you can easily copy the updated table to the other database using the macro.
  37. @@
  38. To create a macro in Access, you click the @UNew@u button on the Macros tabbed page in the Database window.
  39. |
  40. Alternatively, you can select @UMacro@u on the @UNew Object@u button's drop-down menu from any window in the database.
  41. |
  42. The top pane of the Macro window is where you define your new macro.
  43. |
  44. You start by selecting a macro action from the drop-down list in the Action column.
  45. |
  46. The bottom pane of the Macro window is for entering arguments (settings) for your chosen macro action.
  47. |
  48. The right-hand side of the Action Arguments pane displays a brief help message, which changes depending on where in the window the cursor is located.
  49. |
  50. You can press @UF6@u to move from one pane to the other.
  51. |
  52. In the Destination Database field, you type the full path of the database to which you want to copy the object.
  53. |
  54. When you use the @UTab@u key to move to the next field, the help message changes accordingly, telling you to enter a new name or leave the field blank to retain the current name.
  55. |
  56. The Source Object Type drop-down list allows you to choose the type of database object (in this case @UTable@u) you want to copy.
  57. |
  58. The Source Object Name drop-down now shows the names of all the objects of the selected type in the current database.
  59. |
  60. Remember, you can press @UF1@u at any stage to obtain help.
  61. |
  62. When you place the cursor in the Comment column, you are prompted to type an appropriate comment.
  63. |
  64. This is optional but can prove useful, as you may later need to distinguish this CopyObject macro action from a similar action in another macro.
  65. |
  66. Now you can select a second macro action from the drop-down list in the Action column.
  67. |
  68. You may want to choose @UMsgBox@u, so that you can set up a message box confirming that the first macro action has been carried out.
  69. |
  70. You can now tab to the Comment column and type a comment.
  71. |
  72. Then you switch panes, and type the text you want displayed in your message box in the Message field.
  73. |
  74. If you want a beep to sound when the message box is shown, you select @UYes@u from the drop-down list at the Beep field. 
  75. |
  76. From the Type drop-down list, you choose the type of icon you want the message box to show.
  77. |
  78. Next you type the title you want to appear in the title bar of your message box.
  79. |
  80. You must save a macro before you can run it, so you choose @UFile - Save@u (or click the @USave@u button) to save it in the current database.
  81. |
  82. You can save a macro in another database by selecting @USave As/Export@u from the @UFile@u menu.
  83. |
  84. After entering a name for the macro in the Save As dialog box, you click @UOK@u.
  85. @@
  86. Access 97 provides a way for you to test your macro actions in single steps.
  87. |
  88. To activate single-stepping, you click the @USingle Step@u button on the Macro toolbar (or choose @URun - Single Step@u).
  89. |
  90. Now you click the @URun@u button (or select @URun - Run@u).
  91. |
  92. Access now opens the Macro Single Step dialog box before executing each step.
  93. |
  94. In this dialog box you will see the macro name, macro action, and action arguments associated with a particular step - in this case the first step.
  95. |
  96. You click the @UStep@u button to carry out the macro action named in the Action Name field.
  97. |
  98. If you click the @UContinue@u button, all the remaining steps in the macro will be carried out - here we do not wish to do that.
  99. |
  100. The next macro action is now shown in the Macro Single Step dialog box.
  101. |
  102. You could use the @UHalt@u button to prevent any further steps in the macro from being activated.
  103. |
  104. Here, let's run the next action - you click the @UStep@u button.
  105. |
  106. The message box you designed using the MsgBox macro action is now shown (and a beep sounds, as requested).
  107. |
  108. You click @UOK@u to remove the message box.
  109. |
  110. Finally you can click the @UClose Window@u button to return to the database window.
  111. @@
  112. Sometimes you may want to convert a macro you designed in Access to a VBA (Visual Basic for Applications) module.
  113. |
  114. To do this you choose @USave As/Export@u from the @UFile@u menu.
  115. |
  116. The top radio button is selected by default in the @USave As@u dialog box.
  117. |
  118. You select the @USave as Visual Basic@u @UModule@u radio button and click @UOK@u.
  119. |
  120. Then you click the @UConvert@u button.
  121. |
  122. The Modules tabbed page becomes active in the Database window, and a message box tells you that the conversion is finished - you click @UOK@u to remove the Macro to VBA Conversion dialog box.
  123. |
  124. When you click @UOK@u the converted macro is available on the Modules tabbed page.
  125. |
  126. You click @UDesign@u to open the VBA module.
  127. |
  128. Now you can see the converted macro in Visual Basic.
  129. |
  130. You click the @UClose Window@u button to return to the Database window.
  131. @@
  132. Usually, when you open a database in Access 97, the Database window is not usually maximized.
  133. |
  134. You can create a simple macro to maximize the Database window automatically when you open a file.
  135. |
  136. Access 97 runs a macro automatically (on opening the database) if you name the macro "AutoExec".
  137. @@
  138. Normally you would run a macro directly (for example, from the Macro window, or Database window) only to test it.
  139. |
  140. You can run a macro from the Database 
  141. window by selecting @UMacro - Run Macro@u 
  142. from the @UTools@u menu. (If the Macros 
  143. tabbed page is not active, or if no macro 
  144. is selected on the Macros tabbed page, 
  145. you will be prompted to choose the macro 
  146. you want to run.)
  147. |
  148. After that, you could create a custom menu command or toolbar button to run a macro.
  149. |
  150. You can also attach a macro to a form, report, or control so that it runs in response to an event.
  151. |
  152. An event is an action, such as a mouse click or key press, or the opening of your database.
  153. |
  154. Suppose you would like to add a command to the @UTools@u menu to run the macro "Copy Sales to Product Info".
  155. |
  156. First you choose @UView - Toolbars - Customize@u (or right-click the toolbar or menu bar, and click @UCustomize@u).
  157. |
  158. Now you click the @UCommands@u tab in the Customize dialog box.
  159. |
  160. You use the scroll bar in the Categories box to find the category of command you wish to add to the menu.
  161. |
  162. When you select @UAll Macros@u from the list, the macros in the database are displayed in the Commands box.
  163. |
  164. You select the macro you require, and drag it towards the @UTools@u menu.
  165. |
  166. When you drag the command over the @UTools@u menu, the usual menu commands appear - you point to where you want the command to be placed on the menu (where you see the black line).
  167. |
  168. When you release the mouse, the command is shown on the menu.
  169. |
  170. Finally, you click the @UClose@u button in the Customize dialog box.
  171. |
  172. Now you can run the macro from anywhere in the Database window, irrespective of which tabbed page is active.
  173. |
  174. When you point to the @UMacro@u option on the @UTools@u menu, the command you added (to run the macro) is available on the @UMacro@u submenu.
  175. |
  176. To remove the command from the menu, you would first open the Customize dialog box, then click the @UMacro@u option on the @UTools@u menu. You can then right-click the command you wish to remove, and select @UDelete@u from the shortcut menu.
  177. |
  178. You can follow a similar procedure to add a button for running a macro to a toolbar.
  179. |
  180. Suppose you would like to place a button on the Standard toolbar for running the macro "Copy Sales to Product Info".
  181. |
  182. With the toolbar to which you want to add the button showing, you open the Customize dialog box, and select the required command.
  183. |
  184. You then drag the command to the position (indicated by the black line) where you want to place the button on the toolbar.
  185. |
  186. When you release the mouse, the button is inserted on the toolbar, inside a heavy black outline.
  187. |
  188. You can click the @UModify Selection@u button to customize the button.
  189. |
  190. For example, you may want to change the icon shown on the button.
  191. |
  192. Then you click @UClose@u to return to the Database window.
  193. @@
  194. Another way that you can run a macro is by assigning an action (or set of actions) to a specific key combination.
  195. |
  196. Then Access carries out the action(s) when you press the key combination.
  197. |
  198. Suppose you would like to use a key combination to take you back five records in your Customers form.
  199. |
  200. You begin by using the @UNew Object@u button to create a new macro.
  201. |
  202. Next you click the @UMacro Names@u button (or select @UView - Macro Names@u).
  203. |
  204. This inserts a Macro Name column to the left of the Action column, allowing you to create a @Rgroup@r of named macros.
  205. |
  206. A macro group can contain a single named macro, but in general macro groups contain more than one macro.
  207. |
  208. You type @R%004^5@r in the Macro Name field to assign the key combination @UCtrl+5@u to the macro.
  209. |
  210. If you assign a set of actions to a key combination already used by Access (for example, @UCtrl+S@u is the key combination for Save), your assignment will override the Access key assignment.
  211. |
  212. Then you select the macro action you require - in this case @UGoToRecord@u.
  213. |
  214. When you have chosen the action arguments needed to go to the fifth previous record, you click the @USave@u button (or choose @UFile - Save@u).
  215. |
  216. In this case the required arguments are
  217.  
  218. ò Object Type - Form
  219.  
  220. ò Object Name - Customers
  221.  
  222. ò Record - Previous
  223.  
  224. ò Offset - 5
  225. |
  226. The name you enter in the Macro Name field will actually be the name of the macro group you are creating.
  227. |
  228. You must call the macro group AutoKeys in order to run the macro you named %004^5 using the key combination @UCtrl+5@u.
  229. |
  230. You click @UOK@u to save the macro group AutoKeys.
  231. |
  232. The new key assignment is ready to use, and you can click the @UClose Window@u button.
  233. |
  234. Now you can test the new key assignment on the Customers form.
  235. |
  236. When you press @UCtrl+5@u, the fifth previous record is shown.
  237. @@
  238. Suppose you wish to use the key combination @UCtrl+F@u to open the Customers form.
  239. |
  240. You can do this by adding a key combination called %004^F to an appropriate macro group.
  241. @@
  242.