Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

You can create a macro (macro: An action or set of actions that you can use to automate tasks.

) to perform a specific action or a macro group (macro group: A collection of related macros that are stored together under a single macro name. The collection is often referred to simply as a macro.) to perform a series of actions.

Create a macro

1.

In the Database indo (Database

indo : The indo that appears hen you open an

Access database or an Access pro!ect. It displays shortcuts for creating ne database ob!ects and opening e"isting ob!ects.)# click Macros $. %. under Objects. toolbar.

Click the New button on the Database indo

Add an action (action: The basic building block of a macro& a self'contained instruction that can be combined ith other actions to automate tasks. This is sometimes called a command in other macro languages.) to the macro.

(o )

1.

In the *acro indo (*acro indo : The indo in hich you create and modify macros.)# click the first empty ro in the Action column. If you ant to insert an action (action: The basic building block of a macro& a self'contained instruction that can be combined ith other actions to automate tasks. This is sometimes called a command in other macro languages.) bet een t o action ro s (action ro : A ro in the upper part of the *acro indo in hich you enter macro names# actions# conditions# and comments associated ith a particular macro or macro group.)# click the selector for the action ro !ust belo you ant to insert the ne action# and then click Insert Row on the toolbar. the ro here

2.

In the Action column# click the arro to display the action list (action list: The list that appears hen you click the arro in the Action column of the *acro indo .).

%.

Click the action you ant to use. In the lo er part of the indo # specify arguments for the action# if any are re+uired. ,or action arguments (action argument: Additional information re+uired by some macro actions. ,or e"ample# the ob!ect affected by the action or special conditions under hich the action is carried out.) hose settings are a database ob!ect (database ob!ects: An Access database

4.

contains ob!ects such as tables# +ueries# forms# reports# pages# macros# and modules. An Access pro!ect contains ob!ects such as forms# reports# pages# macros# and modules.) name# you can set the argument by dragging the ob!ect from the Database indo (Database The indo indo :

that appears hen you open an Access database or an Access pro!ect. It displays

shortcuts for creating ne database ob!ects and opening e"isting ob!ects.) to the action-s Object Name argument bo". .. Type a comment for the action. Comments are optional. To add more actions to the macro# mo/e to another action ro part of the *acro indo (action ro : A ro in the upper

4.

in hich you enter macro names# actions# conditions# and comments

associated ith a particular macro or macro group.) and repeat step %. *icrosoft Access carries out the actions in the order you list them.

Create a macro group

If you ant to group se/eral related macros (macro: An action or a set of actions you can use to automate tasks. *acros are recorded in the 0isual 1asic for Applications programming language.) in one place rather than keeping track of them separately# you can organi2e them as a macro group.

1.

In the Database indo (Database

indo : The indo that appears hen you open an

Access database or an Access pro!ect. It displays shortcuts for creating ne database ob!ects and opening e"isting ob!ects.)# click Macros $. under Objects. toolbar.

Click the New button on the Database indo Click Macro Names

3.

on the toolbar# if it isn-t already selected (selected: A toolbar button

al ays has a border around it hen it-s selected# e/en hen the pointer is not resting on the button.). 3. .. In the Macro Name column# type a name for the first macro in the macro group. Add the actions (action: The basic building block of a macro& a self'contained instruction that can be combined ith other actions to automate tasks. This is sometimes called a command in other

macro languages.) you ant the macro to carry out.

(o )

1.

In the *acro indo (*acro indo : The indo in hich you create and modify macros.)# click the first empty ro in the Action column. If you ant to insert an action (action: The basic building block of a macro& a self'contained instruction that can be combined ith other actions to automate tasks. This is sometimes called a command in other macro languages.) bet een t o action ro s (action ro : A ro in the upper part of the *acro indo in hich you enter macro names# actions# conditions# and comments associated ith a particular macro or macro group.)# click the selector for the action ro !ust belo you ant to insert the ne action# and then click Insert Row on the toolbar. the ro here

2.

In the Action column# click the arro to display the action list (action list: The list that appears hen you click the arro in the Action column of the *acro indo .).

%.

Click the action you ant to use. In the lo er part of the indo # specify arguments for the action# if any are re+uired. ,or action arguments (action argument: Additional information re+uired by some macro actions. ,or e"ample# the ob!ect affected by the action or special conditions under hich the action is carried out.) hose settings are a database ob!ect (database ob!ects: An Access database

4.

contains ob!ects such as tables# +ueries# forms# reports# pages# macros# and modules. An Access pro!ect contains ob!ects such as forms# reports# pages# macros# and modules.) name# you can set the argument by dragging the ob!ect from the Database indo (Database The indo indo :

that appears hen you open an Access database or an Access pro!ect. It displays

shortcuts for creating ne database ob!ects and opening e"isting ob!ects.) to the action-s Object Name argument bo". .. 4. Type a comment for the action. Comments are optional. 5epeat steps 3 and . for any you ant to include in the macro group.

6"amples of macro conditions


You can use any e"pression (e"pression: Any combination of mathematical or logical operators# constants# functions# and names of fields# controls# and properties that e/aluates to a single /alue. 6"pressions can perform calculations# manipulate characters# or test data.) that e/aluates to True7,alse or Yes78o in a macro condition (condition: 9art of the criteria that a field must meet for searching or filtering. :ome conditions must be used ith a /alue& for e"ample# the field Author ith the condition equals macro ill be e"ecuted if the condition e/aluates to True (or Yes). ith the /alue ;ane.). The

Tip

To cause *icrosoft Access to temporarily ignore an action (action: The basic building block of a macro& a self'contained instruction that can be combined ith other actions to automate tasks. This is sometimes called a command in other macro languages.)# enter ,alse as a condition. Temporarily ignoring an action can be helpful hen you are trying to find problems in a macro.
Use this expression [City]="Paris" To carry out the action if Paris is the City value in the field on the form from which the macro was run. $here are more than "# entries in the OrderID field of the Orders ta%le. $here are more than three entries in the Order Details ta%le for which the OrderID field of the ta%le matches the OrderID field on the Orders form. $he value of the )hi**edDate field on the form from which the macro is run is no earlier than -.'e%.-//0 and no later than -.2ar. -//0. $he value of the 3nitsIn)toc4 field on the Products form is less than five. $he 'irst6ame value on the form from which the macro is run is Null (Null7 1 value you can enter in a field or use in e8*ressions or 9ueries to indicate missin: or un4nown data. In ;isual +asic, the Null 4eyword indicates a Null value. )ome fields, such as *rimary 4ey fields, can<t contain Null. (has no value . $his e8*ression is e9uivalent to ['irst6ame] Is Null. $he value in the Country field on the form from which the macro is run is 3=, and the value of the $otalOrds field on the )ales$otals form is :reater than 0//. $he value in the Country field on the form from which the macro is run is 'rance, Italy, or )*ain, and the *ostal code isn<t five characters lon:.

DCount("[OrderID]", "Orders" !"#

DCount("&", "Order Details", "[OrderID]='orms([Orders]([OrderID]" !"

[)hi**edDate] +etween ,-.'e%.-//0, 1nd ,-.2ar.-//0,

'orms([Products]([3nitsIn)toc4]5#

Is6ull(['irst6ame]

[Country]="3=" 1nd 'orms([)ales$otals]( [$otalOrds]!0//

[Country] In ("'rance", "Italy", ")*ain" 1nd >en([PostalCode] 5!#

2s:+o8("Confirm chan:es?",0 =0

@ou clic4 OK in a dialo: %o8 in which the MsgBox function dis*lays "Confirm chan:es?". If you clic4 Cancel in the dialo: %o8, 2icrosoft 1ccess i:nores the action.

You might often ant to look at related records on t o forms at the same time. ,or e"ample# hile looking at a customer record on a Customers form# you might ant to open an <rders form that sho s the customer-s orders.

=hen you mo/e bet een records on a form# you might also ant to automatically /ie related records on a second form. ,or e"ample# as you mo/e bet een supplier records on a :uppliers form# you might see the products each supplier carries in a 9roducts form. ant to

You can synchroni2e records bet een t o forms by creating a command button that opens and synchroni2es a second form# or by using the Current e/ent to display related records on the second form hen you mo/e bet een records on the first form.

You can also use the ,orm =i2ard to create t o related forms from scratch.

You can use the ,orm =i2ard to create t o related forms from scratch.

1.

In the Database indo (Database

indo : The indo that appears hen you open an

Access database or an Access pro!ect. It displays shortcuts for creating ne database ob!ects and opening e"isting ob!ects.)# click Forms $. %. under Objects. toolbar

Click the New button on the Database indo

In the New Form dialog bo"# click the Form Wizard.

You don-t need to specify the record source (record source: The underlying source of data for a form# report# or data access page. In an Access database# it could be a table# +uery# or :>? statement. In an Access pro!ect# it could be a table# /ie # :>? statement# or stored procedure.) for the forms here. You can do this in the i2ard.

3. ..

Click OK. Click the name of the first table or record source that includes the data you ant to base your first form on. :elect the fields to be included on your form.

4.

After selecting the fields from the first table or record source in the ,orm =i2ard# repeat step . to select another table or record source# and pick fields that you ant to include in your second form.

@. A. B.

=hen you ha/e selected all the re+uired fields# click Next. In the second screen of the i2ard# click Lin ed !orms# and then click Next. ,ollo the instructions in the i2ard. The i2ard creates the t o related forms& each form

contains fields from one of the record sources. <ne of the forms also has a command button that opens the other form and synchroni2es the records bet een the forms.

If the resulting forms don-t look the ay you ant# you can change them in Design /ie (Design /ie : A indo that sho s the design of these database ob!ects: tables# +ueries# forms# reports# macros# and data access pages. In Design /ie # you can create ne database ob!ects and modify the design of e"isting ones.).

You might also like