What event happens when jumping from form to form? (2 Viewers)

Happy YN

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2002
Messages
425
The following is a quote from MS VB help:-

Note The Activate event doesn't occur when a form receives focus back from a dialog box, popup, or another form.

My question is so what event occurs if a form gets the focus from another form?
I tried the got focus event and put a breakpoint there but it does not seem to be running that code!
Thanks
 

ajetrumpet

Banned
Local time
Today, 17:37
Joined
Jun 22, 2007
Messages
5,638
The following is a quote from MS VB help:-

Note The Activate event doesn't occur when a form receives focus back from a dialog box, popup, or another form.
This is right, as the Activate event refers to the Form being opened, or "loaded". It's just an "initiation" event (as I call them).
My question is so what event occurs if a form gets the focus from another form?
GetFocus occurs, nothing else.
I tried the got focus event and put a breakpoint there but it does not seem to be running that code!
Running what code? The code you put behind the form under the Activate event? if you're trying to run such code, and your form is already open, you can't, per my first note.
 

unclejoe

Registered User.
Local time
Tomorrow, 06:37
Joined
Dec 27, 2004
Messages
190
Here's from Help.

GotFocus, LostFocus Events

The GotFocus event occurs when a form or control receives the focus.

The LostFocus event occurs when a form or control loses the focus.

Note The GotFocus and LostFocus events apply only to forms and controls on a form, not controls on a report.

Remarks

To run a macro or event procedure when these events occur, set the OnGotFocus, or OnLostFocus property to the name of the macro or to [Event Procedure].

These events occur when the focus moves in response to a user action, such as pressing the TAB key or clicking the object, or when you use the SetFocus method in Visual Basic or the SelectObject, GoToRecord, GoToControl, or GoToPage action in a macro.

A control can receive the focus only if its Visible and Enabled properties are set to Yes. A form can receive the focus only if it has no controls or if all visible controls are disabled. If a form contains any visible, enabled controls, the GotFocus event for the form doesn't occur.

You can specify what happens when a form or control receives the focus by running a macro or an event procedure when the GotFocus event occurs. For example, by attaching a GotFocus event procedure to each control on a form, you can guide the user through your application by displaying brief instructions or messages in a text box. You can also provide visual cues by enabling, disabling, or displaying controls that depend on the control with the focus.

Note To customize the order in which the focus moves from control to control on a form when you press the TAB key, set the tab order or specify access keys for the controls.

The GotFocus event differs from the Enter event in that the GotFocus event occurs every time a control receives the focus. For example, suppose the user clicks a check box on a form, then clicks a report, and finally clicks the check box on the form to bring it to the foreground. The GotFocus event occurs both times the check box receives the focus. In contrast, the Enter event occurs only the first time the user clicks the check box. The GotFocus event occurs after the Enter event.

The LostFocus event differs from the Exit event in that the LostFocus event occurs every time a control loses the focus. The Exit event occurs only before a control loses the focus to another control on the same form. The LostFocus event occurs after the Exit event.

If you move the focus to a control on a form, and that control doesn't have the focus on that form, the Exit and LostFocus events for the control that does have the focus on the form occur before the Enter and GotFocus events for the control you moved to.

If you use the mouse to move the focus from a control on a main form to a control on a subform of that form, the following events occur:

Exit (for the control on the main form)

ß

LostFocus (for the control on the main form)

ß

Enter (for the subform control)

ß

Exit (for the control on the subform that had the focus)

ß

LostFocus (for the control on the subform that had the focus)

ß

Enter (for the control on the subform that the focus moved to)

ß

GotFocus (for the control on the subform that the focus moved to)

If the control you move to on the subform previously had the focus, neither its Enter event nor its GotFocus event occurs, but the Enter event for the subform control does occur. If you move the focus from a control on a subform to a control on the main form, the Exit and LostFocus events for the control on the subform don't occur, just the Exit event for the subform control and the Enter and GotFocus events for the control on the main form.

Note You often use the mouse or a key such as TAB to move the focus to another control. This causes mouse or keyboard events to occur in addition to the events discussed in this topic.

When you switch between two open forms, the Deactivate event occurs for the first form, and the Activate event occurs for the second form. If the forms contain no visible, enabled controls, the LostFocus event occurs for the first form before the Deactivate event, and the GotFocus event occurs for the second form after the Activate event.

The following is a quote from MS VB help:-
Note The Activate event doesn't occur when a form receives focus back from a dialog box, popup, or another form.
My question is so what event occurs if a form gets the focus from another form?
I tried the got focus event and put a breakpoint there but it does not seem to be running that code!
Thanks
 

Happy YN

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2002
Messages
425
Thats helpful unclejoe BUT if a form has visible controls etc , what event can you fire so when a form gets the focus then a particular control should set itself to a value?
The form can sometimes be opened on its own or sometimes be switched to from another form after being opened.
Thanks again for all your help
 

unclejoe

Registered User.
Local time
Tomorrow, 06:37
Joined
Dec 27, 2004
Messages
190
Let’s just say this, if the main form has button to open a PopUp message, you’ll have no problem with the OnActivate Event. But if you’ll open another form from the Database window, the OnActivate will not work on the previous form because the form is or may not be in focus.

So, generally, you’ll have no problems with the OnActivate Event if all your forms are opened by the Main Form or through another form.

If you need to open a form through the Database Window, use the form’s OnClose or OnDeactivate Event to set the Focus on that particular form.

A simple code will suffice.

Forms!YourFormName.SetFocus

Thats helpful unclejoe BUT if a form has visible controls etc , what event can you fire so when a form gets the focus then a particular control should set itself to a value?
The form can sometimes be opened on its own or sometimes be switched to from another form after being opened.
Thanks again for all your help
 
R

Rich

Guest
Use IF (isLoaded) "SomeForm" Then
etc
 
Last edited:

Happy YN

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2002
Messages
425
Thanks for the replies but I still seem to be missing something.:confused:

My situation is that often I have two forms open and I am switching from one to the other. As I switch to "form B" from "form A" I want to set certain values in controls on form B. I am looking for the event which I can use to trigger this.
Activate - doesn't work if the form is already open
nor will open or load.
Got focus will not work because there are controls on the form as uncle joe wrote.
So what can I use?
I presume Rich's comment is addressing the aspect of the form sometimes being opened on its own merit and sometimes from another form but I cannot see how this solves the above problem.
Looking forward to a solution!
Happy YN
 

unclejoe

Registered User.
Local time
Tomorrow, 06:37
Joined
Dec 27, 2004
Messages
190
When you said, “As I switch to "form B" from "form A"”. Do you mean by mouse clicking on the “formB”?

So far, the OnActivate Event works on A2K version. In my test, the OnActivate fires up nicely in the event.

Unless I misunderstood, please clarify how would you want the data to be transferd form "formA" to "formB". I don't see why the OnActivate event does not work for you.

Thanks for the replies but I still seem to be missing something.:confused:
My situation is that often I have two forms open and I am switching from one to the other. As I switch to "form B" from "form A" I want to set certain values in controls on form B. I am looking for the event which I can use to trigger this.
Activate - doesn't work if the form is already open
nor will open or load.
Got focus will not work because there are controls on the form as uncle joe wrote.
So what can I use?
I presume Rich's comment is addressing the aspect of the form sometimes being opened on its own merit and sometimes from another form but I cannot see how this solves the above problem.
Looking forward to a solution!
Happy YN
 

evanscamman

Registered User.
Local time
Today, 15:37
Joined
Feb 25, 2007
Messages
274
I always use the on-activate event - it fires each time the form receives focus.

Evan
 

ajetrumpet

Banned
Local time
Today, 17:37
Joined
Jun 22, 2007
Messages
5,638
The following is a quote from MS VB help:-

Note The Activate event doesn't occur when a form receives focus back from a dialog box, popup, or another form.
I just tested this. The above quote seems to be wrong. The event does fire. So, I guess it's not just restricted to the opening of the form object. :rolleyes:
My situation is that often I have two forms open and I am switching from one to the other. As I switch to "form B" from "form A" I want to set certain values in controls on form B. I am looking for the event which I can use to trigger this.
Activate - doesn't work if the form is already open
Seems like you're the only one it doesn't work for Happy. You got any code in the background of the form that might be preventing this? I have no idea what it would be though (just to let you know ahead of time).
 

Happy YN

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2002
Messages
425
Thanks for replies!
When clicking a control in form A, I pick up some values from form A (into public variable) and open form B and then set control in B to that value.
That works fine if form B is opening for the first time but if it is already open, just behind form A I can't get the event to fire. As mentioned I put a breakpoint in the on activate and in the got focus events but the code does not stop there so it seems not to be firing those events?
I doubt the vb help I posted originally re the on activate is wrong and ajetrumpet bore this out!
Thanks for all the interest & help but I'm not thru the woods yet!
 

evanscamman

Registered User.
Local time
Today, 15:37
Joined
Feb 25, 2007
Messages
274
If you add an event from the VBA editor instead of from the Properties window in Access, sometimes the form won't know the code is there.

Look at the events in the properties window for your form and make sure it is listed.

Evan
 

Happy YN

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2002
Messages
425
Checked that
Still no joy!
Am I missing something obvious
Thanks to you all for your interest
 

Happy YN

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2002
Messages
425
If I set the tab order for a label (for example) to be the first, then could I run code on the get focus of that control? Just an idea!
 

Happy YN

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2002
Messages
425
Nope! Doesn't work. firstly a label has no tab index and even when I set a text box to be the first in tab index it does not automatically get the focus when the form is viewed.
Ajetrumpet you asked for a visual. what do you want to see? My code in form_gotFocus. the whole Db would be too cumbersome to send!
Thanks for all the interest.
I think if I get nowhere I will have no option but to close down the form each time I switch forms so when I switch back it re-opens; and the code for that IS working.
 

unclejoe

Registered User.
Local time
Tomorrow, 06:37
Joined
Dec 27, 2004
Messages
190
Here's form Help.

Note The Activate event doesn't occur when a form receives focus back from a dialog box, popup, or another form. The Deactivate event doesn't occur when a form or report loses the focus to a dialog box, to a form for which the PopUp property is set to Yes, or to a window in another application.

One thing i can come up with, is that your form property is set to PopUp or Modal. Is any of your form set to it or any code in both the forms is causing error?

It might be better that you display the code here so that we help you further.

Thanks for replies!
When clicking a control in form A, I pick up some values from form A (into public variable) and open form B and then set control in B to that value.
That works fine if form B is opening for the first time but if it is already open, just behind form A I can't get the event to fire. As mentioned I put a breakpoint in the on activate and in the got focus events but the code does not stop there so it seems not to be firing those events?
I doubt the vb help I posted originally re the on activate is wrong and ajetrumpet bore this out!
Thanks for all the interest & help but I'm not thru the woods yet!
 

Happy YN

Registered User.
Local time
Today, 23:37
Joined
Jan 27, 2002
Messages
425
I think I've solved it!
Thanks to your prodding I re-examined all the code and found that the command button switching between forms had docmd.minimize code in its click event so that when I switched to the other form it would minimze itself.
As such, when the form was switched on again it was really just maximizing itself again (not getting the focus). I put a breakpoint in the resize event and it stops there each time!
I don't remember why I put a minimize there (I wrote this part a few years ago!). Perhaps its unnecessary because opening another form would automatically send it to the back but I suppose if it was bigger it would stick out from behind & it would not look nice so I minimized it!
Thanks everyone for your help suggestions and interest
A happier Happy YN:):):)
 

ajetrumpet

Banned
Local time
Today, 17:37
Joined
Jun 22, 2007
Messages
5,638
Thanks to your prodding I re-examined all the code and found that the command button switching between forms had docmd.minimize code in its click event so that when I switched to the other form it would minimze itself.
Well, I'm glad to hear that my program is running smoothly. I'm sure glad there are no bugs in it! :)
 

Users who are viewing this thread

Top Bottom