Searching for the Correct Event (1 Viewer)

TheSearcher

Registered User.
Local time
Today, 00:50
Joined
Jul 21, 2011
Messages
304
I have Form1 and Form2.
If a user is on Form1 and they click a command button to bring them to Form2 I want a message box to appear in certain circumstances.
I tried putting the message box in the On Open, On Load, On Current, On Activate and On Got Focus events of Form2.
In every instance the message box appears between Form1 closing and Form2 opening.
What do I need to do to have the message box appear on Form2?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 05:50
Joined
Feb 19, 2013
Messages
16,618
Not clear what you mean - those events occur before the form becomes visible. Suggest use a timer for a second or two before displaying your message
 

TheSearcher

Registered User.
Local time
Today, 00:50
Joined
Jul 21, 2011
Messages
304
Interesting. Microsoft docs contradict that (Regarding On Current, On Activate and On Got Focus). Thanks for the tip about the timer. I'll either use that or a label to display my message.
 

LarryE

Active member
Local time
Yesterday, 21:50
Joined
Aug 18, 2021
Messages
592
  1. Create a texbox control on form2
  2. In the Control Source property enter: =IIf(This condition is true, "Message",Null)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:50
Joined
Feb 28, 2001
Messages
27,194
A form becomes visible just after the user portion of the OnLoad event, but the controls do not have contents until the OnCurrent event. Usually this is so fast that you don't see the difference. I once (unwisely) overloaded the OnCurrent event with too much stuff that could have gone in OnLoad and I could see blank controls briefly. With regard to your form's GotFocus event, that doesn't fire unless the form has NO enabled controls that could deal with data - either bound OR unbound. If a form has a viable control, the first control in tab order always gets focus unless there is a control.SetFocus in play.

That message box SHOULD become visible after the form is displayed IF you fire it from the OnCurrent event.

As a fine point, though, depending on exactly what MsgBox options you used, the box technically might not appear on EITHER of the forms. It might appear on the overall video workspace. This would be the case, for example, if you chose the System Modal option.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 00:50
Joined
May 21, 2018
Messages
8,536
One potential way to do this is to put the message in the calling form's code
Code:
Private Sub Command0_Click()
  DoCmd.OpenForm "frmTwo"
  MsgBox "Hi. I am displaying after " & Forms!frmTwo.Name & " is visible"
End Sub
The above works as long as you do not open frmTwo in windowmode ACDIALOG. ACDIALOG causes the code in the calling form to halt until the called form is closed.

Since the called form (frmTwo) is open you can call also use any property or method in frmTwo. In the above case I reference the name property.
But you can also call a method in frmTwo. So put a method in frmTwo that you want to call after frmtwo is visible.

assume your method is in FrmTwo
Code:
Public Sub DisplayName()
  MsgBox "My name is " & Me.Name
End Sub

Then call from frmOne
Code:
Private Sub Command0_Click()
  DoCmd.OpenForm "frmTwo"
Forms!frmTwo.DisplayName
End Sub
 

TheSearcher

Registered User.
Local time
Today, 00:50
Joined
Jul 21, 2011
Messages
304
Thank you to all for your help! I decided to use a label and make it visible from the On Open event of Form2. It seems that controls obey the proper sequence of events. Message boxes - not so much!
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 05:50
Joined
Sep 12, 2006
Messages
15,658
I have Form1 and Form2.
If a user is on Form1 and they click a command button to bring them to Form2 I want a message box to appear in certain circumstances.
I tried putting the message box in the On Open, On Load, On Current, On Activate and On Got Focus events of Form2.
In every instance the message box appears between Form1 closing and Form2 opening.
What do I need to do to have the message box appear on Form2?

A msgbox isn't on the form that calls it. It's a modal popup message on the desktop. It's not even confined by the Access workspace. You can move it anywhere on the desktop.

So if you have

Code:
open form1

open form2

open a msgbox to show a message - this will now be shown while both form 1 and form 2 are both open.
It doesn't matter whether you call this on form 1 or form 2
It's modal and will stay open until you close it, and only then

close form 1


so instead you could just open a new form, with a message, from either form 1 or form 2
this is not modal, and the code will continue to run.

Code:
open form1

open form2
open a new msgform with a message (from code here, or code within form2)

close form 1

now form 1 will close while the msgform is open, and the user will have to close the msgform when they have read the message.
Or you can add code to form 2 to close the msgform on a timer, or some other way.
 
Last edited:

Users who are viewing this thread

Top Bottom