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

SetFocus function call errors

Status
Not open for further replies.

scrix1

Programmer
Apr 20, 2001
2
GB
I have had a problem with an application which occasionally produced runtime error 5 (invalid procedure call/access denied).
To resolve this is resorted in adding line by line tracing to find where the problem was occuring only to find the statement was 'txtField.SetFocus'.
This statement works 99% of the time, but when it produces the error the only way to resolve is to re-boot.

Has anyone seen this before ? Any ideas as to what could be causing it ?

scrix1
 
Yep - you'll get this if you either

a) Try to set the focus to an invisible control, or
b) Try to set the focus to a control that already has it.

Try using this test...

if (me.ActiveControl is cntrl or cntrl.visible=false) then cntrl.SetFocus

mmilan
 
This works fine and avoids the errors, I'm now getting an error on the next statement 'me.hide'.
Is there a better way of hiding the form, such as 'frmName.hide' and is there any error checking I can perform around this ?

S.
 
You will also want to make sure that the form (the one hosting the control or the one you are trying to .Hide) is Enabled. Otherwise, the 'invalid procedure call' message will ensue.

RS
 
>>b) Try to set the focus to a control that already has it.

If this were true then wouldn't the following code produce an error:

Code:
Private Sub Form_Load()
    Me.Show
    Text1.SetFocus
    Text1.SetFocus
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top