SetFocus

Posted by: UndeadBob

SetFocus - 10/17/03 12:06 PM

hey all,

my first VB assignment at uni works fine except for one thing. When the program starts it runs until it gets to SetFocus and then gives me a Run time error '5' an invalid procedure call or argument.

Code:
 Private Sub Form_Load()
    optBackColour1.Value = True
    optTextColour1.Value = True
    optFont1.Value = True
    optPointSize1.Value = True
    txtStyles.SetFocus
End Sub

Private Sub optBackColour1_Click()
    txtStyles.BackColor = &HFFFFFF
    txtStyles.SetFocus
End Sub 
when it starts it reads the Form_Load code and skips to the optBackColour1_Click sub be qives me the error when it gets to txtStyles.SetFocus

any help will be appreciated.....
Posted by: SilentRage

Re: SetFocus - 10/18/03 01:18 AM

The moment I saw the title "SetFocus" I just knew what the question would be. There's only one error I've ever gotten with SetFocus and that is when you're trying to give a control Focus when it isn't visible. The Form_Load event fires before the Form_Activate event and therefor is not visible at the time.
Posted by: BackSlash

Re: SetFocus - 10/18/03 09:19 PM

you can put in form1.show before the setfocus, that should fix it
Posted by: UndeadBob

Re: SetFocus - 10/19/03 12:40 AM

thanx guys for your help. it was bugging me beause i just couldn't see what was wrong