Can anyone explain why Text1.SetFocus and Form1.SetFocus give an error message, even though I have Text1 textbox and Form1 available?
Error is:
'Run-time error 5: Invalid procedure call or argument'
-lp
Printable View
Can anyone explain why Text1.SetFocus and Form1.SetFocus give an error message, even though I have Text1 textbox and Form1 available?
Error is:
'Run-time error 5: Invalid procedure call or argument'
-lp
That is interesting! I am new at this too and
I tried what you said and I have the same
error. However, if you place text1 and text2
in your form, but if you add the following lines
to your project, and then click text1, your
focus will goto text2 without any error.
Private Sub Text1_Click()
Text2.SetFocus
End Sub
To me it seems like you must have something
in ordor to eliminate the error and the truth I
don't know either.
I am not sure, but what Service Pack for Visual BAsic are you running? You might need to get the latest one from Microsoft (MSDN network). The latest version is Service Pack 4.
Hope this helps
The .SetFocus method is nothing new and does not require service pack 4.
However, if you are attempting to do it in the Form_Load event, you will get an error.
From VB Help:
If this is what you are doing, move the code to Form_Activate and it should work.Quote:
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 can't use the SetFocus method to move the focus to the form being loaded in its own Load event unless you first use the Show method to show the form before the Form_Load event procedure is finished.
Post again if that doesn't help...
You will get the same error even after the form is loaded if the form for some reason is not visible (like after MyForm.Hide) or if there is a modal form showing in front of it.
Strange. The following code works fine.
Post the code that you are getting an error on. Maybe it's in error in your codeCode:Private Sub Text1_Click()
Text2.SetFocus
End Sub