• Welcome to Valhalla Legends Archive.
 

Set Focus help..

Started by OuTLawZGoSu, December 21, 2003, 02:41 PM

Previous topic - Next topic

OuTLawZGoSu

Why doesn't this work?



Private Sub Form_Load()
Form1.Setfocus
End Sub



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?

Grok

Quote from: OuTLawZGoSu on December 21, 2003, 02:41 PM
Why doesn't this work?

Private Sub Form_Load()
   Form1.Setfocus
End Sub


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?

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

Private Sub Form_Load()
   Me.Show
   Me.Setfocus
End Sub


hismajesty

Why wouldn't the form have focus when it loads anyway?

Grok

Quote from: hismajesty on December 22, 2003, 12:07 AM
Why wouldn't the form have focus when it loads anyway?

Because it has no window to receive the focus.

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.

Grok

Quote from: OuTLawZGoSu on December 22, 2003, 09:22 AM
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.

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


Private Sub Button1_Click()
   Form2.Show
   Button1.SetFocus
End Sub


Tested and works.

OuTLawZGoSu

Yes! thx a lot. Works just fine ^^