Combo Box controls

A

alex451

I have a very simple form with two combo boxes on. When the form opens
it automatically goes to one of the combo boxes.


However I can simply tab from one combo box to the next without having
selected anything from the list.

I want to be able to ensure that the first combo box has something
selected before going to the second combo box and then the second combo
box must have something before going to either the next free text field
(which does not have to have anything) or to the add/save button.

I do not leave the form to create a new record just press add record.
 
G

Guest

This is a little complex. The reason is no change has been made to the
combo, so the before upate event will not fire. Your first thought might be
to check the value of combo1 in the gotfocus event of combo2. The problem
is, a user does not have to use the tab key. He can use the mouse to point
to a different control which would bypass that logic. Using the LostFocus
event of combo1 will not work, because it can't be canceled and to make
matters worse, you can't set the focus to a control that has the focus.

One way to do this is create a hidden control you will use to handle this.
In the LostFocus event of combo1:
If IsNull(Me.Combo1) Then
Me.HiddenControl.SetFocus
End If

Then in the GotFocus event of the hidden control, you need to be able to
allow the user to get out of the form if necessary:

If IsNull(Me.Combo1) Then
If MsgBox("Entry Required - OK to retry on Cancel to Close Form", _
vbOkCancel) = vbCancel Then
DoCmd.Close
Else
Me.Combo1.SetFocus
End If
End If

Do the same for both combos
 

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