I have a combobox where I don't want the user to leave the control null so I put this code in the LostFocus event:
Code: Select all
Private Sub Service_LostFocus()
If IsNull(Me.Service) Then
MsgBox "Please provide a Type of Service"
Me.Service.SetFocus
Exit Sub
End If
Set oCtrl = Me.Service
DeactivateCtrl oCtrl
End Sub
One thing that might affect this is that this is a subform which must have one but can have more records and I don't know how to refer to the current record instead of the entire field. The key field (SvcProvidedID) is included in the subform footer, but I don't know how to incorporate it in the reference. What's more, this is the first control for each record in the subform, so upon entry there's no key field ID assigned. That's why I'm trying to localize the code to the active control.
Another thing that might be relevant is that it is not an unbound combobox. The control source is a field (Service) in a table (tblSvcItems).
(FYI, the 'DeactivateCtrl' procedure just removes shading I use to indicate the active control.)
- Jeff