Access using macro control program 3. Use Conditions in macros
Access using macro control program 3. Use Conditions in macros
In some cases, you may want to perform one or more operations in a macro only when the specified condition is true. For example, if a macro is used to verify data in a form, the corresponding information may be displayed to respond to certain input values of the record, and the other information to respond to different values. In this case, you can use conditions to control the macro process. The condition is a logical expression. Macros are executed along different paths based on the true or false condition results. If this condition is true, Microsoft Access performs the operation in this row. Enter the ellipsis (…) in the condition column of the operation that follows this operation (...), Microsoft Access can perform these operations when the condition is true. If the result of this condition is false, microsoft Access ignores this operation and is followed by a ellipsis (…) in the condition field (...) And move to the next operation that contains other conditions or empty "condition" fields.
Create a form, add a text box, name it "input number text box", and add a confirmation button. Click the OK button property event/click the generator button on the right, select create macro, and create a macro name for the macro, such as "macro 3 ".
Is the design view of macro 3. This macro displays different messages based on different numbers entered in the [enter number text box. Click the "condition" button on the toolbar.
To add a condition column for The Macro. The first line in the figure indicates that when 0 <[enter a number text box] <10, a message "you entered a number less than 10" is displayed. The second line indicates that when 10 <[enter a number text box] <20, a message "you entered a number greater than 10 and less than 20" is displayed. The third line indicates that when 20 <[enter a number text box] <30, a message "you entered a number smaller than 20 and less than 30" is displayed. Close the macro design view and save macro 3.
This is the result of the form running. When a number of 15 is entered, the message box will be displayed.