Microsoft Access Tips for Serious Users

Provided by Allen Browne, 1994. (Note: Access 2000 introduced conditional formatting options as well.)


Properties at Runtime: Forms

In Access version 1, only a few properties such as Visible and Enabled were editable when the application was running. In later versions, only a handful of properties are not available at runtime, so you can use the Current event of a form or the Format event of a report section to conditionally alter the formatting and layout of the data, depending on its content.

For example, to highlight those who owe you large amounts of money, you could add this in a form's Current event:

    With Me.AmountDue
        If .Value > 500 Then
            .Forecolor = 255
            .Fontbold = True
            .Fontsize = 14
            .Height = 400
        Else
            .Forecolor = 0
            .Fontbold = False
            .Fontsize = 10
            .Height = 300
        End If
    End With

screenshot

Some of the changes you can perform are rather radical, such as changing the record source of a form while it is running! You might do this to change the sort order, or - with astute use of SQL - to reduce network traffic from a remote server.

In addition, some controls have properties which do not appear in the "Properties" list at all, since they are available only at runtime. For example, combo boxes have a "column()" property which refers to the data in the columns of the control. Picture a combo box called cboClient with 3 columns: ID, Surname, Firstname. When not dropped down, only the ID is visible, so you decide to be helpful and add a read-only textbox displaying the name. DLookup() will work, but it is much more efficient to reference the data already in the combo by binding your textbox to the expression:

    = [cboClient].[Column](2) & " " & [cboClient].[Column](1)

Home Index of tips Top