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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 SetFocus and Windows XP - error 5 1

Status
Not open for further replies.

Paddyo

Programmer
Jun 27, 2002
140
IE
Hi

I have a problem when running executable code under Windows XP.

Sometimes i get an 'invalid procedure call or Argument' Error 5, when I try to set the focus to a control.

Im my code I check to see if the control is enabled and only then do I try to set the focus to it - but sometimes I still get the error.

Is this a problem with Windows XP - Im confident my code is correct. I have read else where that a doevents might solve the porblem. However I do not really want to use the DoEvents.

has anyone else come up with this problem and if so was there a resolution to it.

Thank you in advance
Paul


 
Please verify that the control is LOADED, AND VISIBLE at the time of SetFocus. Probably, by doing

if ctrl.Visible then ctrl.SetFocus

will avoid timing problems related with events being processed out of order we expected!

I hope this help you

Lucky
Carlos Paiva
 
Thanks for replying Paiva

The control is indeed loaded and visible.

The program and code works fine most of the time, infact it works all of the time on Windows 98 machines.

The error occurs imtermittantly.

Paul
 
Hi

I'm having the same problem but mine occurs constantly.
I've just seen that the object is not visible even though it is...
ie

if text1.visible=true then
msgbox("visible")
end if

I'm trying to find a solution
 
Hi Paul

Managed to work around it

I've had to show the form before all the objects could getfocus

Hope it helps...

Rakesh Singh
AIX/Linux Div. STANLIB
 
I dont think this will solve my problem.

The form is already loaded and details have been entered.

The user clicks the save button, the data is saved and then I want to disable lots of controls, enable the control I want to set the focus and then set the focus.

Quite striaght forward - but does not work all of the time.

Glad you got your problem sorted.

Paul
 
Mine occured on a logon dialog
Error appeared when trying to setfocus on the password textbox when an incorrect password was entered
Even though the form was loaded and visiible, I requested a frmlogon.show (on the theory that the objects visiblity state could not be correctly determined) and the error vanished.

Good luck
 
Thanks for the replies

I think I will try the visibility property.

My other problem is that I cannot get it to happen. Its only happening on customers sites. So testing is a reall problem.

I will let you know how I get on

Paul
 
Hi Again

Well we finally got the error to happen in our offices maybe once out of every 20 times.

After taking the suggestion of rzs0502 to put in a formname.show before the setfocus we could not get the error to happen again. So thank you for you help. You deserve a star.

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top