Link to home
Start Free TrialLog in
Avatar of Yury Merezhkov
Yury MerezhkovFlag for United States of America

asked on

Form onLoad question

Hi guys,

why am I getting this error - "Invalid procedure call or argument?"

Private Sub Form_Load()
    If App.PrevInstance Then
        MsgBox "The application is already running!", vbCritical, "Error!"
        End
    End If
   
    Me.SSTab1.Tab = 0
    Me.StoreName0.SetFocus  'Error here!
   
    For i = 0 To 6
        Me.Controls("SetPoint" & i).AddItem "Occupied"
        Me.Controls("SetPoint" & i).AddItem "Unoccupied"
    Next i
   
End Sub

Thanks.
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

This assumes there are combo boxes SetPoint0, SetPoint1, SetPoint2, ..., SetPoint6
If any of those are missing or a different type of control, that would cause an invalid procedure error.
>    Me.StoreName0.SetFocus  'Error here!
Whoops, didn't see the 'Error here! part.
Make sure StoreName0 is a control, and is typed correctly, and is not a control array such as StoreName(0)
Avatar of Yury Merezhkov

ASKER

StoreName0 is a simple textbox. It's not a control array. It's typed correctly. Very strange.
I can do this:

Me.StoreName0.Text = "TEST"

but setfocus just won't work.
ASKER CERTIFIED SOLUTION
Avatar of jkaios
jkaios
Flag of Marshall Islands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>I can do this: Me.StoreName0.Text = "TEST"  but setfocus just won't work.
Some wild guesses...  Is Enabled = True?  Locked = False?  Visible = True?
But if you still want to set the focus on the control at the Form_Load event, you simple force Load event to finish by using the Show method.

Private Sub Form_Load()
    Me.Show                     '<-- CALL THIS METHOD FIRST B4 SETTING THE FOCUS TO ANY CONTROL
    Me.SSTab1.Tab = 0
    Me.StoreName0.SetFocus
End Sub