|
-
Nov 8th, 2000, 05:02 PM
#1
Thread Starter
Member
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
-
Nov 8th, 2000, 05:14 PM
#2
Hyperactive Member
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.
-
Nov 8th, 2000, 05:16 PM
#3
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
-
Nov 8th, 2000, 05:23 PM
#4
Frenzied Member
When are you trying to set focus?
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:
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.
If this is what you are doing, move the code to Form_Activate and it should work.
Post again if that doesn't help...
-
Nov 8th, 2000, 06:28 PM
#5
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.
-
Nov 8th, 2000, 07:38 PM
#6
Strange. The following code works fine.
Code:
Private Sub Text1_Click()
Text2.SetFocus
End Sub
Post the code that you are getting an error on. Maybe it's in error in your code
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|