Chapter 19: Advanced Access Form Techniques
691
Visible property is initially set to No, making it invisible. Then the following code runs every
time the form’s Timer event fires:
Private Sub Form_Timer()
lblRed.Visible = Not lblRed.Visible
lblBlue.Visible = Not lblBlue.Visible
End Sub
This code simply alternates the Visible property of each of the label controls. Since lblRed was
initially invisible, it’s made visible in the first pass, and so on. Although there are many other ways
to implement this form trick, this example adequately demonstrates the value of the Not operator
when dealing with property values.
Caution
Be careful using flashing labels. They’ve been known to cause problems for people with epilepsy.
Creating an auto-closing form
If you want a form to close automatically as soon as the user moves to another form, do the
following:
- Create an event procedure for the Deactivate event that includes the following
statement:
Me.TimerInterval = 1 - Create an event procedure for the Timer event that includes the following statement:
DoCmd.Close
Your form automatically closes as soon as you go to any other form.
Setting up combo boxes and list boxes
Combo boxes and list boxes are powerful tools in your form-building toolbox, but they can be
complicated to set up. When you build combo boxes and list boxes, it’s important to keep in mind
the distinction between ControlSource (the table or query field to and from which the control
saves and loads data) and RowSource (the source of the data displayed in the list). Because
combo and list boxes support multiple columns, they allow you to easily relate data from another
table without basing your form on a query that joins the tables. This technique, which involves a
bound combo- or list-box control that stores an ID number but displays names in a list, is used in
the Organization combo box in the form named frmContacts_Northwind in Chapter19.
accdb, as well as in several of the forms found in the Northwind sample database.
For example, suppose you’re creating a form to display information about your clients and custom-
ers (your “contacts”), and you want to identify the organization with which these contacts are asso-
ciated. In a well-designed database, you store only an organization ID number with each contact
record, while you store the organization’s name and other information in a separate table. You