After Update Control

The AfterUpdate event occurs after the data in the control has been modified. It applies to text boxes, combo and list boxes, option buttons, check boxes, and bound object frames. Unlike the BeforeUpdate event, the AfterUpdate event cannot be cancelled. Use this event to fill in other controls on the form based on the newly entered or selected value.

For example, after updating the cboSiteId combo box in the Site Information section of the Asset Management sample form, the following event procedure is executed:

Private Sub cboSiteId_AfterUpdate() With Me

.txtSchoolName = Me.[cboSiteId].Column(1) .txtStreet = Me.cboSiteId.Column(2) .txtCity = Me.cboSiteId.Column(3) .txtState = Me.cboSiteId.Column(4) .txtZip = Me.cboSiteId.Column(5) .cboRooms.Value = vbNullString .cboRooms.Requery

.txtRoomDescription = vbNullString .cboRoomType = vbNullString

Part IV

.cboOS = vbNullString .txtOperatingSystem = vbNullString .cboProject = vbNullString .txtPID = vbNullString End With

If Me.cboRooms.ListCount = 0 Then ' do not display column headings Me.cboRooms.ColumnHeads = False


Me.cboRooms.ColumnHeads = True End If

Me.cboRooms.SetFocus End Sub

In the procedure shown above, the school address information is filled in based on the contents of the cboSiteld columns. For example, to fill in the street address, you can read the value of the Columns() property of the cboSiteld control, even though this column is not visible when you view the combo box:

Me.txtStreet = Me.cboSiteId.Column(2)

Note that because the combo box column numbering begins with zero (0), the above statement actually reads the contents of the third column. Next, the combo box labeled "Room No" is requeried and a number of other controls on the form are cleared.

Also, note how the intrinsic constant named vbNullString is used here instead of an empty string ("") to clear text boxes or combo boxes on a form. The final code segment above contains the If.. .Then.. .Else statement that sets the ColumnHeads property of the cboRooms control to False if there are no rooms associated with the selected Site ID. The last line of the code

Me.cboRooms.SetFocus moves the focus to the combo box control with the room numbers. When this code is executed, the cboRoom_Enter event procedure will be triggered.

0 0

Post a comment