In Microsoft Access 1.1, few properties could be changed at run time. Most properties required flipping the object back into design mode. This is no longer needed for Microsoft Access 2.0. In Microsoft Access 2.0 you can change almost all object properties at run time. To see if a particular property can be set at run time, please consult the Help file.
The power of this feature is obvious. You can change the definition of an object as it runs. For example, you can change the RecordSource for a form or the ControlSource for a control. In the Orders form of the sample database you can see two example uses of run-time settable properties.
Clicking the Single View / Datasheet view button will change the subform for the order details. It switches between two different subforms by changing the subform control's SourceObject property at run time. It also changes the Caption property of the command button.
These changes occur on the Click event for the command button. The code for this event procedure appears below. The code for this in the database is in the form module for the Orders form.
Sub SubformView_Click () 'Flip to the other view of the subform. Do this based on the 'SourceObject property of the subform control. If (FlipSubform.SourceObject = "Order Details Single") Then 'Need to change from single form view to data sheet. Also update 'the caption of the button FlipSubform.SourceObject = "Order Details Datasheet" SubformView.Caption = "Datasheet view" Else 'Need to change from data sheet view to single form. Also update 'the caption of the button FlipSubform.SourceObject = "Order Details Single" SubformView.Caption = "Single view" End If End Sub
The second example is the same Orders form. Selecting the different items in the form source list box will result in a different query being used for the form's RecordSource property. The code for this follows:
Sub FormSource_AfterUpdate () Dim NewSource As String 'Check the value of the list box and update the source 'based on this value If FormSource.Value = "Orders made before 1992" Then NewSource = "qryOrdersBefore92" ElseIf FormSource.Value = "Orders made after 1992" Then NewSource = "qryOrdersAfter92" Else NewSource = "qryOrdersIn92" End If 'If the source selected by the user is different than the 'current source then change the RecordSource property to 'reflect this. If (Me.RecordSource <> NewSource) Then Me.RecordSource = NewSource End Sub