Results 1 to 5 of 5

Thread: GotFocus/LostFocus & Forms

  1. #1

    Thread Starter
    Member
    Join Date
    May 1999
    Location
    St. Louis, MO, USA
    Posts
    54

    Post

    I'm having problems capturing when a form has focus and when it loses focus. I have an app that has several different forms. when the user is finished with one form I need to close it. I thought I could do this with the lostfocus event however I am not able to get the form to respond to it.

    Could someone please explain when a form has focus.

    Example code

    Private Sub form1_GotFucus()



  2. #2
    Member
    Join Date
    Jan 1999
    Location
    Garden Grove, CA, Orange
    Posts
    55

    Post

    A form receives the focus only when all visible controls are disabled.

    Try this example

    Have 2 forms and on the form1 place a command button.

    Code:
    Private Sub Form_Click()
    Form1.SetFocus
    End Sub
    
    Private Sub Form_GotFocus()
    MsgBox "Form1 got focus"
    End Sub
    
    Private Sub Form_Load()
    Command1.Enabled = False
    Form2.Show
    End Sub
    
    Private Sub Form_LostFocus()
    MsgBox "Form1 lost focus"
    End Sub
    May be u can try form Activate events instead

    Joon

  3. #3
    New Member
    Join Date
    Sep 1999
    Location
    Boise, ID USA
    Posts
    15

    Post

    if you only need to use one form at a time, then i just usually disable all other forms. go like this:

    private sub form_load
    otherform1.enabled=false
    otherform2.enabled=false
    otherform3.enabled=false
    end sub

    private sub form_unload
    otherform1.enabled=true
    otherform2.enabled=false
    otherform3.enabled=false
    me.enabled=false
    end sub

    or you could create a public sub that disables all the forms in your app except the one you pass to it:

    public sub DisableInActiveForms (EnabledForm as form)
    form1.enabled=false
    form2.enabled=false
    form3.enabled-false
    form4.enabled=false

    enabledform.enabled=true
    end sub

    this sets each form in your app as disabled and then sets the one you want enabled enabled.

    Adam

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    You can also place this in the GotFocus event of your other forms
    Code:
    If Screen.ActiveForm.Name <> "form1" Then
        MsgBox "focus is no longer on form1"
    End If
    ------------------
    Marty

  5. #5

    Thread Starter
    Member
    Join Date
    May 1999
    Location
    St. Louis, MO, USA
    Posts
    54

    Post

    Thanks for your help everyone. I found the form_activete event the most usefull for what I'm trying to do. When my main/parent form is actived I simply hide all of the other/child forms.

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