Software

Use macros to control what form your Access application opens

Do you use one Access form on Mondays and a different one on Thursdays? If you use variable pricing or other fluctuating data structures, learn how you can set a macro to open the right Access form for the appropriate circumstance.

You create an application that automatically opens an online order form in Access when a button on the application screen is pressed. The form that opens should reflect the prices that are in effect on the order date.

Here's an example: Your company runs specials each weekend. On the weekends, your online customers should use the order form with the weekend prices; on the weekdays, customers should see the weekday prices. To create a macro that will automatically open the correct form, follow these steps:

  1. In your Database window, click the Macros Under the Objects bar and then click New.
  2. Click the Conditions button in the Macro toolbar.
  3. Click in the first cell of the Condition column and enter:
  4. Weekday(Date())=0 Or Weekday(Date())=7
  5. Click [Tab] and select OpenForm.
  6. In the Form text box, select WeekendOrderForm.
  7. Click in the second cell of the Condition column and enter:
  8. WeekDay(Date())<>0 And Weekday(Date())<>7
  9. Click [Tab] and select OpenForm.
  10. In the Form text box, select WeekdayOrderForm.
  11. Save the macro as OpenOrderForm.

To create a button in your online shopping form that will open the correct order form, follow these steps:

  1. Open the form in Design view.
  2. Click the Command Button tool in the Forms toolbox.
  3. Click and drag where you want the button to appear in your form.
  4. In the Command Button Wizard window, select Form Operation under Categories.
  5. Click OpenForm under Actions.
  6. Click Next three times.
  7. Click in the Text box and enter Click Here to Order.
  8. Click Next.
  9. In the Command label field, enter Get Orders Form.
  10. Click Finish.
  11. Right-click the selected Command button in your form and click Properties.
  12. Click in the Onclick Property under the Event tab and select the OpenOrderForm macro.

Miss a tip?

Check out the Microsoft Access archive, and catch up on our most recent Access tips.

Help users increase productivity by automatically signing up for TechRepublic's free Microsoft Office Suite newsletter, featuring Word, Excel, and Access tips, delivered each Wednesday.

Editor's Picks

Free Newsletters, In your Inbox