 |
Sample product checking macro
runs every time you save and checks for oversights
The following is a good example of a simple, but very useful macro which runs automatically every time you close a product record. Basically it checks for oversights and so helps to ensure that your data is kept in good order.
Humans are notoriously bad at learning rules, remembering them and making sure that they get applied every time. Consequently, in common with, we are told, the rest of the universe, all data files tend naturally to move towards chaos. Macros can make a tremendous difference, because they can make sure that rules get applied every time and that data is checked for completeness and consistency.
This little macro has two sections. The first uses a simple 'If' statement to check whether the product has been assigned an analysis code; if it has not then it gives it a default analysis code.
The second section uses a 'Case' statement to say 'if this is true, then do this; or if this is true then do this; or if this is true..' and so on. Here we are using it to make sure that the Maintain Stock field on the Product record is correctly set. This field defines whether you automatically create Stock Movements when you order items, deliver them, and so on. Left to human error, it is easily over looked or wrongly entered. Using a macro, you simply define your rules in the macro and the macro makes sure they are implemented correctly every time.
The Macro is called Accept 9. This is important because it tells the system to run it every time you accept (i.e. save) a record in table 9 (the Products table).
By using the first three characters of the Product Code, followed by an '@' sign (which means 'anything') The first three characters are also the Group Code. So
:([PRODUCTS]Product Code="TRA@")
means 'if the Group Code is TRA [Travel] (the rest of the Product Code can be anything)'
[PRODUCTS]Maintain Stock:=False
Means 'Then uncheck the Maintain Stock checkbox. You can add as many of these two line statements as you like. Here there are more for Administration Charges, Expenses, and Deliveries. The Else statement says what happens if you find nothing in the list which is true.
A word of warning about macros in general: if you are writing your own, or modifying any we supply, make sure that you test them on a dummy data file. Macro writing is a skilled job, for people conversant with 4D coding, though, as in this case, you can often achieve a lot with a little.
The Daybook Team do offer an expert macro writing service, for those people who don't like do-it-yourself.
Finally bear in mind that to run macros, you will have to have purchased the Macros volume. Each user of the system for whom the macro is to run will also need to have the Play Data Entry Macros option turned on in the Access Rights section of his or her Personnel record.
So here is the macro:
MACRO CODE: Accept 9
SAME PROCESS MACRO selected
MACRO TEXT
If([PRODUCTS]Analysis Code="")
`Replace the question mark in the next line with your own default analysis code
[PRODUCTS]Analysis Code:="?"
End if
Case of
:([PRODUCTS]Product Code="TRA@")
[PRODUCTS]Maintain Stock:=False
:([PRODUCTS]Product Code="ADM@")
[PRODUCTS]Maintain Stock:=False
:([PRODUCTS]Product Code="EXP@")
[PRODUCTS]Maintain Stock:=False
:([PRODUCTS]Product Code="DEL@")
[PRODUCTS]Maintain Stock:=False
Else
[PRODUCTS]Maintain Stock:=True
End case
Back
to main newsletter »
|
|