Approach User Support homepage Approach User Support
Answers to Frequently Asked Questions about Lotus Approach
Examples LotusScripts
Example databases
Links to other Lotus Approach support services

[Return to contents]

Looping macros

Last updated: 27 Apr 2005 by XpertSS.com

(Including sequentially numbering a set of records and making global changes to a set of records)

This FAQ demonstrates macros implemented in Approach V3, 96 or 97 or any of the "Millennium Edition 9.x" releases. Macros were implemented differently in prior versions of Approach, so if you used version 1 or 2, you will need to spend some time in the help files / manual of Approach to accomplish a similar result.

Broadly speaking, a looping macro (which may consist of several individual macros working together) does the following:

This sequence of steps means that the operation is performed on every record in the current found set. Conditions can be added to the operations so that they are only performed under certain conditions. For example, if you wanted to add a 6 to all of the phone numbers starting with a 5, then your macro would include the statement:

    SET db.phonenumber to If(Left(db.phonenumber,1)='5', Combine('6',
db.phonenumber),db.phonenumber)

   (where "phonenumber" is a text field)

Often it is necessary to have a macro that precedes the looping macro to set up the conditions that the loop needs for its correct operation. (I'll call this a Control macro). This may do things such as:

The last operation of the looping macro always runs the looping macro again (NOT THE CONTROL MACRO) This is demonstrated below, but first...

To carry information from one record to the next you need to use variable fields. For instance, if you want to sequentially number a set of records you need to know what number the previous record was in order to set the number of the current record.

The following example demonstrates both the use of a Control Macro and a Variable to sequentially number a set of records:

  1) Create a numeric field 'VarIDNumber' to hold the sequential number, and a variable field 'VarID' to use in calculating the sequential numbers.

  2) Create a looping macro 'SequentialLoop'. This macro should do the following:

     For this macro to work properly it needs the Control Macro created in Step 3)

  3) Create a macro 'Sequential numbering' to be the Control Macro. It should do the following:

To execute the looping macro, run the 'Sequential Numbering' macro.

Note: In V2.1 you need to use three macros (it does exactly the same things as shown above, but it just takes 3 macros to do it. In v2.1 it is easy to end up with loop macros containing several macros):

Macro 1:
Set the variable field to 1
Run Macro 2

Macro 2:
Set the numeric field to variable field
Menu Options: Next Record
Run Macro 3

Macro 3:
Set the variable field to variable field + 1
Run Macro 2

Also see 'Record numbering' in this FAQ.

[Return to contents]

© Copyright, JohnBrown, Trademarks, Disclaimer, Acknowledgements.