Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELPPPPP!!!!!Run-time error '5 Invalid Procedure Call Or Argument

Status
Not open for further replies.

ravioli

Programmer
Mar 30, 2004
39
US
I was using this software(VB6.0,CR8) for the last couple of
months with no problem. It all started all of a sudden when the application is trying to pass the control to the next form as I am getting an error "Run-time error '5 Invalid Procedure Call Or Argument ", which really baffles me as I have not made any code changes and it was working perfectly well. This is the code that is being highlighted when I say Debug.

B.Text2.SetFocus
-->Where B is the name of the form, I have written this piece of code in Form A.

Any help will be greatly appreciated.
 
Have you loaded form B before you're setting focus? It seems that you could place the setfocus in the onload portion of form B.
 
You can't do a .SetFocus during Form Load.

If you reference a control on another form and the form isn't loaded, it will be loaded. So perhaps Form B is normally loaded already, but in this case it isn't so it gets loaded by being referenced; and then the error.

You can do a .SetFocus a little later in Form Activate.

Usually there's other ways to do what you want. From what I've read, this type of code will not work in VB.Net.
 
I have already loaded the form B as follows
a.hide
b.show
b.text2.setfocus

It used to work perfectly well, but all of a suddent it stopped working the way it used to. Any idea??

Your help is greatly appreciated
 
1. b.show
2. b.text2.setfocus

The problem is that #1 hasn't finished before #2 gets executed.

You could do:

B.Show
Doevents
Doevents
B.Text2.setfocus

But it would be better to find another method. Is text2 not normally the first control to get focus on Form B?
 
no it all depends on the action on form A, based on some
conditional checking on form A I will set the focus to Text1 or text2. Its how my forms are working, if the user selects adding items in form A then I will set the focus to Text1, if the user selects to retrieve an item from database in Form A then I want to load/populate the Form B and setfocus on Text2.
 
Put a public property or a public variable on Form A.

In Form B's Activate Event

If FormA.property = 1 then
text1.setfocus
elseif FormA.property = 2 then
text2.setfocus
else...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top