Results 1 to 3 of 3

Thread: Set Focus to Text Box on another form?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Set Focus to Text Box on another form?

    SetFocus from the code module of another form?

    The code below worked a few times during the development of my new application, which is far from finished. Now the compile results in an error message (Invalid procedure call or argument) for the first of the two bold lines below.
    VB Code:
    1. Private Sub cmdClear_Click()
    2.  
    3. Call ArrayResetter
    4. SquareResetRequired = True
    5. ArrayChanged = False
    6. [B]frmSquare.txtCell(0).SetFocus[/B]
    7.  
    8. End Sub
    9. Private Sub cmdFill_Click()
    10. [B]. . . .[/B] ‘A Select Case with some Call Statements not shown here
    11. Call SquareSummer
    12. ArrayChanged = True
    13. SquareResetRequired = False
    14. [b]frmSquare.txtCell(0).SetFocus[/B]
    15.  
    16. End Sub
    When I make the first bold line above into a comment, the compile works with no error messages. TxtCell is a Control Array mostly generated at Run-Time. TxtCell(0) exists at design time.

    The application uses two ordinary (not Midi) forms and a code module. The above code in the code module associated with one Form (frmcontrol), which activates the other Form (frmSquare) by setting focus to a Text Box on the second form. When the first bold line is changed to a comment, the code compiles, and the second form is activated by (I assume) the action of the second bold line.

    I have changed the order of the two subroutines and the same code causes the error message. I have used copy/paste to make certain that the two statements are identical. I am pretty sure the code complied a few times before the trouble started. I forget which code was added just prior to the problem. The code added was in other procedures, so it is hard to imagine that it had any effect.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    If the object is not visible, or not enabled, then it can't receive focus. That's the only thing I can think of.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    CrptcBlade: This is an error produced by Start with full compile, prior to actually using the application. The code is being compiled, not executed. It has to be scope of variables, CPU tic, VB Fubar, Windows 98 glitch, et cetera.

    If the message occurred for both Subroutines, I would assume that I was not allowed to Set Focus to a Text box on another form.

    When I turn the line of code into a comment for one subroutine, the applications compiles and runs. When application is run, focus is set to one form from the other with no problem. It acts as I would expect.

    Both of the subroutines with the problem line of code are Command Button Click events on the same form.

    If somebody described this anomaly to me, I would not believe it happened that way. I seems so weird.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

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