Solved

Form onLoad question

Posted on 2006-11-15
7
697 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:RealSnaD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17951103
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.
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17951108
>    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)
0
 
LVL 7

Author Comment

by:RealSnaD
ID: 17951175
StoreName0 is a simple textbox. It's not a control array. It's typed correctly. Very strange.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Author Comment

by:RealSnaD
ID: 17951190
I can do this:

Me.StoreName0.Text = "TEST"

but setfocus just won't work.
0
 
LVL 12

Accepted Solution

by:
jkaios earned 500 total points
ID: 17951194
You can only move the focus to a visible form or control. Because a form and controls on a form aren't visible until the form's Load event has finished, you CANNOT use the SetFocus method to move the focus to a control on the form being loaded unless you first use the Show method to show the form before the Form_Load event procedure is finished.

To work around the problem, you either have to set the TabIndex property of the StoreName0 control to zero (0) at design time or move this line:
   "Me.StoreName0.SetFocus"
to the Form_Activate() event.
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17951219
>I can do this: Me.StoreName0.Text = "TEST"  but setfocus just won't work.
Some wild guesses...  Is Enabled = True?  Locked = False?  Visible = True?
0
 
LVL 12

Expert Comment

by:jkaios
ID: 17951234
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question