tags:

views:

175

answers:

3

Hi! I want to set focus on a textfield on one form, from another form. How do I accomplish this in VB6?

A: 

You can not set focus to a text field on another form if that form is not visible. So you should check first if the form is visible

If (form2.Visible)
begin
 txtBox2.SetFocus()
end
J Angwenyi
A: 

Assuming that FormA wants to set the focus on Text1 on FormB I think you could just do something like:

In FormB create a sub called FocusOnText1 and in that sub have the code Text1.SetFocus and then just call that sub from FormA.

As Jangwenyi says though, you need to make sure it's visible, so I'd suggest adding something like his if statement in the FocusOnText1 sub since otherwise you might get errors (Error 5 I think).

ho1
+1  A: 

assuming you have Form1 and Form2 with a TextBox on Form2 in the command1_click of Form1-Modul:

Private Sub Command1_Click()
    Load Form2
    Form2.Show
    Form2.SetFocus
    If Form2.Text1.Visible And Form2.Text1.Enabled Then
        Form2.Text1.SetFocus
    End If
End Sub
Oops