Valhalla Legends Forums Archive | Visual Basic Programming | Set Focus help..

AuthorMessageTime
OuTLawZGoSu
Why doesn't this work?

[code]

Private Sub Form_Load()
Form1.Setfocus
End Sub

[/code]

Everytime the form loads, it tells me, "Invalid Procedure" and highlights "Form1.Setfocus"

This works when I put it in any other command, like Command1_Click()


Help?
December 21, 2003, 8:41 PM
Grok
[quote author=OuTLawZGoSu link=board=31;threadid=4384;start=0#msg36638 date=1072039260]
Why doesn't this work?

[code]Private Sub Form_Load()
Form1.Setfocus
End Sub[/code]

Everytime the form loads, it tells me, "Invalid Procedure" and highlights "Form1.Setfocus"
This works when I put it in any other command, like Command1_Click()

Help?
[/quote]

Cannot set the focus to the form until it is visible. Try this.

[code]Private Sub Form_Load()
Me.Show
Me.Setfocus
End Sub[/code]
December 21, 2003, 10:16 PM
hismajesty
Why wouldn't the form have focus when it loads anyway?
December 22, 2003, 6:07 AM
Grok
[quote author=hismajesty link=board=31;threadid=4384;start=0#msg36688 date=1072073236]
Why wouldn't the form have focus when it loads anyway?
[/quote]

Because it has no window to receive the focus.
December 22, 2003, 1:37 PM
OuTLawZGoSu
This is what I was trying to make.

I got 2 forms. On the first form, I got a button. when i press the button, form2 shows. When form2 shows, it will have focus. I needed a code where, form2 loads and the focus would be set on form1 after form2 has loaded.

Thx a lot, I'm in skool right now so I can't test out the code right now.
December 22, 2003, 3:22 PM
Grok
[quote author=OuTLawZGoSu link=board=31;threadid=4384;start=0#msg36742 date=1072106543]
This is what I was trying to make.

I got 2 forms. On the first form, I got a button. when i press the button, form2 shows. When form2 shows, it will have focus. I needed a code where, form2 loads and the focus would be set on form1 after form2 has loaded.

Thx a lot, I'm in skool right now so I can't test out the code right now.
[/quote]

If you want Form2 to load, but form1 get the focus, do this:

[code]
Private Sub Button1_Click()
Form2.Show
Button1.SetFocus
End Sub
[/code]

Tested and works.
December 22, 2003, 3:32 PM
OuTLawZGoSu
Yes! thx a lot. Works just fine ^^
December 22, 2003, 6:12 PM

Search