Can't Get Message Box to Open After Form Opens (1 Viewer)

JamesJoey

Registered User.
Local time
Today, 02:45
Joined
Dec 6, 2010
Messages
602
I have a message box pop up if a certain value on the for exists display when a form opens.
But, I can't get the msgbox to pop up after the form opens.

I've tried it in the OnLoad, OnOpen and OnActive but the msgbox always pops up before the form opens.

Any way to get it to popup after the form opens??

Jay
 

ashleedawg

"Here for a good time"
Local time
Yesterday, 23:45
Joined
Jun 22, 2017
Messages
154
Put this before your msgbox:

Code:
DoCmd.SelectObject acForm, Me.Name
 

JHB

Have been here a while
Local time
Today, 08:45
Joined
Jun 17, 2012
Messages
7,723
Or use a timer.
Code:
Private Sub Form_Open(Cancel As Integer)
  Me.TimerInterval = 10
End Sub

Private Sub Form_Timer()
  MsgBox ("www")
  Me.TimerInterval = 0
End Sub
 

isladogs

CID VIP
Local time
Today, 07:45
Joined
Jan 14, 2017
Messages
15,661
EDIT: JHB & Ashleedawg both got there quicker but I'll leave this in for a reason which will be obvious if you read on ....

Sometimes you just have to laugh.:D

I tried it & found the same as you.
So I googled it thinking someone must have asked this before

Sure enough I found this exchange here posted by a certain JamesJoey in Nov 2012:
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_access-mso_other/opening-a-message-box-after-the-form-opens/942e64c2-7702-45d9-8928-2032f655f5d3

JamesJoey asked on November 22, 2012
Q:
Opening a Message Box After the Form Opens
I have a message box that works, but it opens before the form.
I've tried the code int the On Load and On Open and On Current.
How do I get the message box to open after the form opens???

Tom van Stiphout replied on November 22, 2012
MVP Insider
A:
That's by design. Here is a workaround:
In the Form_Open set the timer to 1 msec:
Me.TimerInterval = 1
In the Form_Timer event set:
Me.TimerInterval = 0 'stop the timer
MsgBox "Eureka!"

The reason this works is that Timer is a low-priority event, and it happens after all other events are settling down.
-Tom.
Microsoft Access MVP

That's a 'coincidence'. Two JamesJoey's asking EXACTLY the same question 5 years apart

Anyway I tried it and it works

If you want, you can add a short delay e.g. 1 second by adding Sleep 1000 before the MsgBox line in Form_Timer

Code:
Private Sub Form_Open(Cancel As Integer)
    
    Me.TimerInterval = 1
  
End Sub


Private Sub Form_Timer()
    Me.TimerInterval = 0  'stop the timer
    Sleep 1000 'add a 1 second delay
    MsgBox "Eureka!"
End Sub
 
Last edited:

JamesJoey

Registered User.
Local time
Today, 02:45
Joined
Dec 6, 2010
Messages
602
Selecting the form object first worked fine.

Thanks much,
Jay
 

Users who are viewing this thread

Top Bottom