Re: SetFocus a Control...
you can create an array of usercontrols. instead of pasting one usercontrol at a time into a form try to copy the usercontrol that's already pasted in the form, by repeating that procedure you can create an array of usercontrols. in that way, you can reference the control by index which is easy.
Code:
UserControls(0) ' referenced user control 1
UserControls(1) ' referenced user control 2
etc..
however, if you *really* :D want to reference a control by name, like typing the name in a textbox, check the function CallByName.. here is a sample code anyway..
Code:
Dim o As Usercontrol1
Set o = CallByName(Me, "usercontrol" & txt1.text, VbGet)
o.SetFocus
Set o = Nothing
hope that helps :wave:
Re: SetFocus a Control...
In any case you can use a Select Case statement.
Code:
Select Case txt1.Text
Case "1"
UserControl1.SetFocus
Case "2"
UserControl2.SetFocus
End Select
Obviously not the most elegant way to do it, but you can make a Case for every possible occurance.
Re: SetFocus a Control...
You can always just loop through the controls and test for a name match too:
Code:
Dim oCont As Control
For Each oCont In Me.Controls
If LCase$(oCont.Name) = Trim$(LCase$(txt1.Text)) Then
oCont.SetFocus
End If
Next oCont