John Bildy said:
Hi all,
Newbie problems I'm afraid.
I have a combo box on an Orders form which selects customers.
I am trying to create an on_change event. However, the VB window
opens up on a different form (Add Customer). Why would this happen?
How are you going about creating the event procedure? If you just open
the VB Editor, by pressing Alt+F11, for example, that won't create or
open the code module of the form you're working on. The easiest way
(IMO) to create the event procedure you want is to have form open in
design view, open the property sheet of the combo box, go to the Event
tab, and double-click on the line for the event you're interested in.
That should set the event property itself to "[Event Procedure]", at
which point you can click on the builder button (caption "...") at the
end of the line, and you'll be placed in the VB Editor, in the form's
code module, inside the shell of an event procedure constructed for the
purpose. All you have to do is fill in the VBA code that goes between
the "Private Sub" and "End Sub" lines.
Incidentally, I would not use the Change event. That event is fine if
the user uses the mouse to select an item from the dropdown list, but if
the user types in the text box portion of the control, the event will
fire for each keystroke. Instead, use the AfterUpdate event. That will
fire only once, after the user's modification to the control, whether by
keyboard or mouse, has been accepted.
All I want to do is set the focus on another field after a selection
has been made in the combo box. I want the focus to go to employee
field.
I'd expect your event procedure to look something like this:
Private Sub Customer_AfterUpdate()
Me!Employee.SetFocus
End Sub
You'd have to substitute your own control names for "Customer" and
"Employee", naturally.