Results 1 to 6 of 6

Thread: Text1.SetFocus not working(?)

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 1999
    Location
    Houston
    Posts
    48
    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

  2. #2
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    303
    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.


  3. #3
    Guest
    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

  4. #4
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    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...
    ~seaweed

  5. #5

  6. #6
    Guest
    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
  •  



Click Here to Expand Forum to Full Width