PDA

Click to See Complete Forum and Search --> : GotFocus/LostFocus & Forms


Jennifer_R
Dec 21st, 1999, 02:52 AM
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()

jpark
Dec 21st, 1999, 03:44 AM
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.

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

SmashingPumpkinsAddict
Dec 21st, 1999, 03:56 AM
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

MartinLiss
Dec 21st, 1999, 04:04 AM
You can also place this in the GotFocus event of your other forms
If Screen.ActiveForm.Name <> "form1" Then
MsgBox "focus is no longer on form1"
End If


------------------
Marty

Jennifer_R
Jan 18th, 2000, 02:50 AM
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.