HandsOn Using the Enter Event Procedure for the Combo Box Control

1. Open the frmDataEntryMain form in Form view.

2. Click inside the combo box control located to the right of the Room No: label. This action will fire the following Enter event procedure:

Private Sub cboRooms_Enter()

If Me.cboSiteId = "" Or IsNull(Me.cboSiteId) Then MsgBox "Site ID must be specified.", _ vbInformation + vbOKOnly, _ "Missing Site ID" Me.cboSiteId.SetFocus Exit Sub End If End Sub

3. Click OK to the information message generated by the cboRooms_Enter event procedure and notice that the cursor has been positioned inside the combo box control containing Site IDs. Don't make any selections from the Site ID combo box at this time.

Part IV

4. Click on the combo box control next to the Room Type label. This action will fire the following Enter event procedure:

Private Sub cboRoomType_Enter()

If Me.cboSiteId = "" Or IsNull(Me.cboSiteId) Then MsgBox "Site ID must be specified.", _

vbInformation + vbOKOnly, "Missing Site ID" Me.cboSiteId.SetFocus Exit Sub End If

If Me.cboRooms = "" Or IsNull(Me.cboRooms) Then MsgBox "Room number must be specified.", _

vbInformation + vbOKOnly, "Missing Room Number" Me.cboRooms.SetFocus Exit Sub End If End Sub

When the user clicks the cboRoomType combo box control, the Enter event checks whether the cboSiteId combo box control or cboRoom combo box control is empty. If the user did not make a selection in these controls, a message box is displayed and the focus is moved to the appropriate combo box control.

5. Click OK to the information message generated by the cboRoomType_ Enter event procedure and notice that the cursor has again been positioned inside the Site ID combo box control.

0 0

Post a comment