Yury Merezhkov
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.
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.
> 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)
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)
ASKER
StoreName0 is a simple textbox. It's not a control array. It's typed correctly. Very strange.
ASKER
I can do this:
Me.StoreName0.Text = "TEST"
but setfocus just won't work.
Me.StoreName0.Text = "TEST"
but setfocus just won't work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>I can do this: Me.StoreName0.Text = "TEST" but setfocus just won't work.
Some wild guesses... Is Enabled = True? Locked = False? Visible = True?
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
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
If any of those are missing or a different type of control, that would cause an invalid procedure error.