Activate, GotFocus not working ?!

smig

Registered User.
Local time
Today, 23:51
Joined
Nov 25, 2009
Messages
2,209
I open a form as Model+PopUp, using the acDialog option.
from this form I open a second form (As PopUp but not as modal).

I want to know when user move the focus from the second form to the first one (to close the second) but neither the Activate nor GotFocus events (on the first form) are trigered.
They are not even trigered when I first open this form :confused:

I can't use the second form LostFocus event as it never has the focus. this is a "OneClick" form.
 
A Modal form holds the focus until you close it or make it invisible.
 
That's the thing:
It's not Modal, only PopUp.
I can switch to the form that activated the second form.

The Activate, GotFocus not working on the first form
 
You're opening a NonModal form from a Modal form, right? I'm surprised the system will let you move the focus off of the modal form.
 
forget for a moment from the second form

the Activate, GotFocus are not activated even when I first open the first form :confused: (The Activate will run if I open it without the acDialog option)

I just can't find a way to know when I'm back to this form
 
Last edited:
As I've said before, modal forms expect the focus to remain on that form so I'm not real surprised. Have you tried the form with just the PopUp property set and see if you get the results you want?
 
what surprize me is that the GotFocus will not run for a modal+popup form, while it's opened (And as the focus supposed to stay on this formit willn ever run)
Also the Activate will not run if this form is opened using the acDialog option

now back to original question:
you can open a modal form from another modal form. how can you tell when the second one is closed and focus is back to the first one ?

Using the Popup only for the second form is exactly what cause me the problem :D because in this case I can move the focus to the first one, and have no way to know I did (I want to know so I can close the second form)
Tried all kind of events - MouseDown, Click, GotFocus, Activate... nothing seems to work.
 
I guess I just don't see the problem. It sounds like you are trying to man-handle the forms too much. Let each form take care of itself. For example:
now back to original question:
you can open a modal form from another modal form. how can you tell when the second one is closed and focus is back to the first one ?
If the 2nd form is already closed, why do you care?
 
It sounds like you are trying to man-handle the forms too much
Maybe I am :D
Maybe trying to open a non modal form on top of a modal one is not a very good idea.


But can you explain why opening a form using the acDialog option will cause the OnActivate event not to run ?
 
Hint: if all else fails read the instructions. Look in the docs for the events in question.
 
Here is what I found:
If you call a NonModal form from a Modal form you can now move between these two form. Only between these two, and you still left in modal state (No menu, no other forms...)
I think it's very nice for some situations :-)

now back to my original poblem - closing the NonModal form when focus was moved to the Modal one.
The Modal form will not know the focus was moved

I decided to use all the Modal form object's OnMouse down event (I don't use this event for any other purpose.
all is required are two more small functions:
Code:
[FONT=Courier New]Public Sub SetCloseDatePicker(frm As Form)[/FONT]
[FONT=Courier New]On Error Resume Next        ' -- Some objects does not support OnMouseDown event, Some form has no Header/Footer[/FONT]

[FONT=Courier New]Dim ctl As Control[/FONT]
[FONT=Courier New]For Each ctl In frm.Controls
    With ctl
        .OnMouseDown = "=CloseDatePickerForm()"
    End With
Next ctl[/FONT]
[FONT=Courier New][/FONT] 
[FONT=Courier New]frm.Detail.OnMouseDown = "=CloseDatePickerForm()"
frm.Header.OnMouseDown = "=CloseDatePickerForm()"
frm.Footer.OnMouseDown = "=CloseDatePickerForm()"[/FONT]
[FONT=Courier New]End Sub[/FONT]

[FONT=Courier New]' -- this must be a function even though it return no data[/FONT]
[FONT=Courier New]Public Function CloseDatePickerForm()[/FONT]
[FONT=Courier New]If CurrentProject.AllForms("DatePicker").IsLoaded = True Then
    DoCmd.Close acForm, "DatePicker", acSaveNo
End If[/FONT]
[FONT=Courier New]End Function
[/FONT]

I put:
SetCloseDatePicker(me)
in the Form_Open event of the Modal form

all is Good now :)
 

Users who are viewing this thread

Back
Top Bottom