Results 1 to 7 of 7

Thread: [RESOLVED] SetFocus issue !

  1. #1

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818

    [RESOLVED] SetFocus issue !

    OK heres the thing.

    Form A = Main Form
    Form B = Error message

    Form A calls Form B modally.

    If user presses Button 1 on Form B, I want to set the focus on textbox A on Form A.

    Unfortunately, because Form B is called Modally I can't do this.

    So I declare a public Boolean in a module and set it to true on the click of the button, thinking I can check the boolean state in the Activate event of Form A.

    Spotted the obvious error yet ? Even bothered reading this far ?

    The Activate event of Form A isn't called when Form B is closed down, so how do I set my focus ?

    I hope this ones easy
    Last edited by TheBionicOrange; Mar 29th, 2004 at 08:54 AM.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    when code is called to show form B...code should stop at that point untill form B is closed......then continue..

    after code to show form b....check the boolean state and set focus
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818
    Doh !

    And the winner of the "Prize idiot" award goes to me !!!!

    Thannks Static

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    It's better practice to use a private property of a form then a global variable. I would add the following code to Form2.

    VB Code:
    1. Option Explicit
    2. Private mbPressed As Boolean
    3.  
    4. Private Sub Command1_Click()
    5.  
    6.     mbPressed = True
    7.    
    8. End Sub
    9.  
    10. Private Sub Form_Activate()
    11.  
    12.     mbPressed = False
    13.    
    14. End Sub
    15.  
    16. Public Property Get Button1Pressed() As Boolean
    17.  
    18.     Button1Pressed = mbPressed
    19.    
    20. End Property
    21.  
    22. Public Property Let Button1Pressed(ByVal bTF As Boolean)
    23.  
    24.     mbPressed = bTF
    25.    
    26. End Property
    And the code in Form1 would be something like
    VB Code:
    1. If Form2.Button1Pressed Then
    2.     Text1.SetFocus
    3. End If
    Note that Button1Pressed will maintain its value even if Form2 is unloaded.

  5. #5

    Thread Starter
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818
    I never knew they would retain their values even if the form was unloaded !

    Well you learn something new every day !

    Cheers Martin.

  6. #6
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Leave it to Marty to get all "Fancy" on us
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Originally posted by TheBionicOrange
    I never knew they would retain their values even if the form was unloaded !

    Well you learn something new every day !

    Cheers Martin.
    They're like Height, Left or any other property of a form in that respect.

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