Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Abbie Cohen   on Mar 04 In MS Office Category.

  
Question Answered By: Sultana Tabassum    on Mar 04

DataEntryForm.Controls(combobox1).SetFocus

is wrong. The Controls index  should be a string naming the control, or an
integer index into the controls collection. But why not simply do

combobox1.SetFocus

Please also change  your

If combobox1 = "1" Then

to

If combobox1.Value = "1" Then

(If nothing else, this will remind you that you are dealing with an object
that has attributes and methods available.)

The event handler almost certainly got into trouble at the
Controls(combobox1) call. It possibly took the value from the combo box (a
string "1"), converted it to an integer, and set the focus to the first
control. Or it might just have crashed looking for a control called "1".

However, there is also the fact that you are doing this from a text box exit
event, and the move  that caused the exit might happen after the exit event
completes. You might need to set the event's "Cancel" parameter to true to
get it not to do the move. Try without it first, but put it in if you're
still having trouble.

BTW, you don't need Exit Sub in your If statement. Without it, execution
will reach the Else, then jump past the End If and reach the End Sub - which
is what you want to achieve.

Share: