Macros

6
A2 MODULE 6 MACROS & COMMAND BUTTONS A macro is a set of one or more actions that each performs a particular operation, such as opening a form or printing a report. Macros can help you to automate common tasks. For example, you can run a macro that prints a report when a user clicks a command button. 1. In the Database Window, click Macros under Objects. 2. Click the New button on the Database window toolbar. 3. In the Action column, click in the first cell and then click the arrow to display the action list. 4. Browse through the actions you can apply. Below is a list explaining the actions in more detail: Action Details ApplyFlter Restricting data FindNext, FindRecord Move through data GoToControl, GoToPage, GoToRecord Move through data RunCommand Execute a form or report Quit Exit MS Access OpenQuery, RunCode, RunMacro, RunSQL Run a macro, procedure or query RunApp Run another application CanelEvent, Quite, StopAllMacros, StopMacro Stop execution OutputTo, SendObject Export MS Access objects Mrs Neal 23/08/2022

description

 

Transcript of Macros

Page 1: Macros

A2 MODULE 6

MACROS & COMMAND BUTTONS

A macro is a set of one or more actions that each performs a particular operation, such as opening a form or printing a report. Macros can help you to automate common tasks. For example, you can run a macro that prints a report when a user clicks a command button.

1. In the Database Window, click Macros under Objects.

2. Click the New button on the Database window toolbar.

3. In the Action column, click in the first cell and then click the arrow to display the action list.

4. Browse through the actions you can apply. Below is a list explaining the actions in more detail:

Action Details

ApplyFlter Restricting data

FindNext, FindRecord Move through data

GoToControl, GoToPage, GoToRecord Move through data

RunCommand Execute a form or report

Quit Exit MS Access

OpenQuery, RunCode, RunMacro, RunSQL

Run a macro, procedure or query

RunApp Run another application

CanelEvent, Quite, StopAllMacros, StopMacro

Stop execution

OutputTo, SendObject Export MS Access objects to other applications

TransferDatabase, TransferSpreadsheet, TransferText

Transfer data between MS Access and other formats.

CopyObject Copy

Rename Rename

Mrs Neal08/04/2023

Page 2: Macros

Action Details

Save Save

DeleteObject Delete

Maximize Maximize window when opened

Minimize Minimize window when opened

MoveSize Resize a window

Restore Restore

Close Close an object

OpenForm, OpenModule, OpenQuery, OpenReport, OpenTable

Open or an object

OpenForm, OpenQuery, OpenReport, Printout

Print an object

SelectObject Select an object

SetValue Set a value of a field, control or property

RepaintObject, Requery, ShowAllRecords Display updated data or screen

AddMenu To create a custom menu bar, shortcut menu

SetMenuItem Set menu items on the custom menu bar or shortcut menu.

Echo, Hourglass, MsgBox, SetWarnings Display information on screen

SendKeys Generate keystrokes

ShowToolbar Display or hide command bar

Beep Sound of a beep

Put it into Practice:

1. Open a database you have previously created (ensure it includes a form)

Mrs Neal08/04/2023

Page 3: Macros

2. In the Database Window select Macros and click New.

3. Click the drop down box within the Action column, and select Maximize.

4. Save the macro as mrcMax, and close the macro window.

5. Now open a form you have crated in Design View.

6. In the top left hand corner (at the insertion point of the rulers) right-click the black square and select Properties.

7. The Form Properties box is displayed.

8. Click the Event tab.

9. Click On Open.

10. Click the down arrow; a list of macros you have set will be displayed. Choose mcrMax.

11. Close the form.

12. Open the form, you will see the macro runs as soon as the form opens, and the form window is maximised.

Grouping Relating Macros

The following example shows how you can group two macros under one name.

1. You will need to have already created a database, which contains a form.

2. In the database window select Macros and click New.

3. Click the Macros Names icon.

4. A Marco name column will be displayed. Enter the name mcrAddClient.

5. In the Action column select the OpenForm.

6. In the bottom half of the window select the relevant form (Form Name) this specifies which form is to be opened.

Mrs Neal08/04/2023

Page 4: Macros

7. When the form is opened we want to be able to add a new record, therefore we need another action. In the second line of the Action column select GoToRecord, within the Record Action argument select New:

8. Save the macro as mmnuClient.

9. Run the macro by clicking the Run icon on the toolbar.

10. The form should open ready for you to enter a new record.

Command Buttons

You can create a command button on your own, or you can have Microsoft Access create your command button for you using a wizard. A wizard speeds up the process of creating a command button because it does all the basic work for you. When you use a wizard, Access prompts you for information, and then creates the command button based on your answers.

You can create over 30 different types of command buttons by using the Command Button Wizard. For example, you can create a command button that finds a record, prints a record, or save.

1. Open a form in Design View.

2. In the toolbox, click the Command Button tool.

3. On the form, click where you want to place the command button.

4. Follow the directions in the wizard dialog boxes. In the last dialog box, click Finish to display the command button in Design View.

Mrs Neal08/04/2023