Software Catalog:
Macro Magic


Macros are little bits of programming that work as short cuts for the user. Different from general purpose languages such as C, C++, Pascal, or BASIC, application macros are written in a proprietary language supported by that application. Microsoft Access macro programming is hidden from the user in that all one has to do is make selections from drop-down list.

Open a new macro and enter the following items:

Action: 1st line:
Menu Bar:
Menu Name:
Command:
Action: 2nd line:
Menu Bar:
Menu Name:
Command:
Subcommand:
Action: 3rd line:
Action: 4th line:
Menu Bar:
Menu Name:
Command:
DoMenuItem
Form
Records
Save Record
DoMenuItem
Form
Records
Sort
Ascending
ShowAllRecords
DoMenuItem
Form
Records
Refresh

Save the macro as DoRefreshRecords . Close it. This macro saves the new record and refreshes the list in the combo box. We'll link it to forms in a moment.

Open another new macro and enter the following:

Action: 1st line:
Form Name:
View:
Data Mode:
Action: 2nd line:
Record:
Action: 3rd line:
Message:

Beep:
Type:
Title:
OpenForm
Manufacturer Entry/Edit
Form
Edit
GoToRecord
New
MsgBox
Double Click form to refresh records, then double click ombo box.
Yes
Information
Refresh Records

Save this as OpenMfgEntryForm and close it. This macro opens the Manufacturer Entry / Edit Form and moves to a new record waiting for the user to enter data. With the opening of the form from this command button a Message Box is displayed telling the user to double click the form to refresh records. We'll link this to the command button and link the DoRefreshRecords macro to the form double click event.

We need another similar macro. In the database window, select and copy the macro you just saved. Paste it and save it with the name OpenVendorEntryForm . Open the macro in design view and click on the action OpenForm. Change the Form Name to Vendor Entry / Edit . You can choose this from the drop down list. Save it and close it.

Bring the System Entry / Edit form back into view if you minimized it. Select the EnterMfgDataCmd button and click the Event tab of its property sheet. Select the On Click event. Choose OpenMfg-EntryForm macro from the drop down list. Move to another property and SAVE. Now repeat the procedure for the EnterVenDataCmd button and choose the OpenVendorEntryForm macro for the On Click event. SAVE.

We need to force Microsoft Access to refresh records when we finish entering data for a manufacturer or vendor that we need right now. To do that we'll link the DoRefreshRecords macro to the On Dbl Click event for the detail section of each form. Open the design window of Manufacturers Entry / Edit, click anywhere on the grid of the detail section. Turn to the events page of the property list. Choose DoRefreshRecords macro for the On Dbl Click for the event. Repeat for the procedure for Vendors Entry / Edit.

To force the combo boxes to refresh their pick lists to include the newly added records we will link the DoRefreshRecords macro to the On Dbl Click Event of each combo box. In design view on the Systems Entry / Edit form select the combo box for MfgID. Link the DoRefreshRecords macro to the On Dbl Click event. Repeat the procedure for the VenID combo box.

Adjust the tab order: Select menu View | Tab Order. Select and drag until they appear in this order on the list:

  1.  SysName
  2.  SysUser
  3.  CalculatedID
  4.  SysID
  5.  MfgIDCombo
  6.  VenIDCombo
  7.  SysCPU
  8.  SysRAM
  9.  Update
10.  SysSel
11.  EnterMfgDataCmd
12.  EnterVenDataCmd

Recall that each of the tables has a field to hold the data entry or data edit date. This field is useful to keep the user informed of when the data was last updated. The fields are all named Update in every table.

There is no place I can think of where two of these update fields from different tables need appear together. So we really don't need the table identifier prefixes. The common name everywhere will facilitate the creation of a single macro to insert today's date on double click when the data is edited after the initial record creation. We have listed function Date() as the default value for these fields everywhere when the tables were created.

Next create a new macro. In the top row of the action column use the drop down list box and select SetValue. In the lower section of the form Item field type [UpDate] and type Date() in the Expression field. Save the macro as SetDateToday or something easy to remember with that meaning.

The last step of this process is to hook the macro to your forms. Open each of the entry forms, select the text box for the Update field. The control source and name of the text boxes for this field in each form must be named Update for this to work. While you have each of these text boxes selected verify the name and control source, click the event tab and type or select SetDateToday (or whatever you named your new macro) for the On Dbl Click event.

After you have completed this you can simply double click the update field on your forms and your system date will replace the date previously in that field. This is a nice convenience for data entry people.



Return to Beginning
Continue
Previous
This document authored by Pat Tyler
Copyright July 1997