Requiring user data entry

G

Guest

I am attempting to require users to enter data into a specific combo box
before they can fill out the rest of my form. My unbound combo box selects a
record from a member database and is at tab stop 0 so it has the focus when
the form is opened. If users neglect to either enter a member id or select
one from the list in the combo box I want to display a message and return the
focus, and the cursor, to the correct place. I have tried using OnExit and
OnLostFocus and the MsgBox pops up but the focus changes to Tab 1 when what I
want is to stay put. It seems like what I need is a BeforeExit property but
no joy on that score

Private Sub cboSelectMember_LostFocus()
If IsNull(Me.cboSelectMember) Then
MsgBox "You must select a member number"
Me.cboSelectMember.SetFocus
End If
End Sub
 
R

Rick Brandt

Ovus said:
I am attempting to require users to enter data into a specific combo
box before they can fill out the rest of my form. My unbound combo
box selects a record from a member database and is at tab stop 0 so
it has the focus when the form is opened. If users neglect to either
enter a member id or select one from the list in the combo box I want
to display a message and return the focus, and the cursor, to the
correct place. I have tried using OnExit and OnLostFocus and the
MsgBox pops up but the focus changes to Tab 1 when what I want is to
stay put. It seems like what I need is a BeforeExit property but no
joy on that score

Private Sub cboSelectMember_LostFocus()
If IsNull(Me.cboSelectMember) Then
MsgBox "You must select a member number"
Me.cboSelectMember.SetFocus
End If
End Sub

Use OnExit but just set the Cancel argument of the event to True. That cancels
the Exit event so the control never loses focus making it unnecessary to try to
set the focus back.

Private Sub cboSelectMember_Exit(Cancel As Integer)

If IsNull(Me.cboSelectMember) Then
MsgBox "You must select a member number"
Cancel = True
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top