I have a UserForm containing two Frames with 3 combinations of visibility/invisibility.
I have 3 separate codes to control which empty ComboBox takes the SetFocus. (see code below)
I did it this way to address the errors that were being thrown by the empty ComboBoxes in the invisible Frames.
My question is in two parts.
1. How can I make the 3 separate codes into 1?
2. What modification will I have to make when I have a UserForm with both ComboBoxes and TextBoxes?
I would appreciate help from anyone who takes the time.
'When Frame2 is invisible
Sub setFocus1 ()
Dim ctl as MSForms.Control
For each ctl in Frame1.Controls
If TypeName(ctl) = "ComboBox" Then
If ctl.Text = Empty Then
ctl.SetFocus
Exit For
End if
End if
Next ctl
End sub
'When Frame1 is invisible
Sub setFocus2 ()
Dim ctl as MSForms.Control
For each ctl in Frame2.Controls
If TypeName(ctl) = "ComboBox" Then
If ctl.Text = Empty Then
ctl.SetFocus
Exit For
End if
End if
Next ctl
End sub
'When both Frames are visible
Sub setFocus3 ()
Dim ctl as MSForms.Control
For each ctl in Me.Controls
If TypeName(ctl) = "ComboBox" Then
If ctl.Text = Empty Then
ctl.SetFocus
Exit For
End if
End if
Next ctl
End sub
Bookmarks