MsgBox Auto Close

G

Guest

How can I have a MsgBox display for x seconds and then close without user
action?
Would I have a macro do this and if so how? If not can it be displayed and
closed without the user having to click the "OK" button
 
K

Ken Snell [MVP]

You cannot do this with a MsgBox. Create your own form to use as a message
box. Set the Timer Interval for that form to a value that is 1000 times your
"x" value. Have a macro that is associated to the Timer event on that form
close the form. Have a macro open that form when you want to display your
message.
 
D

Douglas J. Steele

The easiest way would be to have your own form that looks like a message
box. Use a timer on the form to close it after a fixed amount of time.
 
G

Guest

I have not been successful in figuring out how to do this. Could you explain
the steps to make it happen. I read a lot of stuff in the MS help file but
nothing seems to work for me.
 
K

Ken Snell [MVP]

Create a new form in design view. Put a label on the form to contain the
message. Click on the label, and open the Properties window; select the
Format tab. Put your desired message in the label's Caption property.

Now, keep the Properties window open. Click on the area beyond the edge of
the form. The Properties window should now be "active" for the form. Click
on the Event tab. Scroll down to the Timer Interval property. Identify how
many seconds you want the form to remain displayed, multiply that by 1000,
and put that number in this box (replace the 0 that is already there); for
example, if you want the form to be open for 5 seconds, put 5000 in that box
(5000 is the number of milliseconds that you want the form to be open).

Then, go to the On Timer property. Click in the box and select [Event
Procedure]. Then click on the three-dot box at far right side of the
textbox. The Visual Basic Editor will open and display two lines separated
by a blank line:

Private Sub Form_Timer()

End Sub

On the blank line, type this:

DoCmd.Close acForm, Me.Name, acSaveNo

Then close the VBE window, save the form (name it frmMsgBox or something
like that).

Now, when your macro opens this form, it will close automatically. Be sure
that you open the form using the Window Mode of Dialog.

--

Ken Snell
<MS ACCESS MVP>
 
G

Guest

ROFLMAO-because I had everything set the way you stated, I forgot the part
about the docmd line. Thanks.

Ken Snell said:
Create a new form in design view. Put a label on the form to contain the
message. Click on the label, and open the Properties window; select the
Format tab. Put your desired message in the label's Caption property.

Now, keep the Properties window open. Click on the area beyond the edge of
the form. The Properties window should now be "active" for the form. Click
on the Event tab. Scroll down to the Timer Interval property. Identify how
many seconds you want the form to remain displayed, multiply that by 1000,
and put that number in this box (replace the 0 that is already there); for
example, if you want the form to be open for 5 seconds, put 5000 in that box
(5000 is the number of milliseconds that you want the form to be open).

Then, go to the On Timer property. Click in the box and select [Event
Procedure]. Then click on the three-dot box at far right side of the
textbox. The Visual Basic Editor will open and display two lines separated
by a blank line:

Private Sub Form_Timer()

End Sub

On the blank line, type this:

DoCmd.Close acForm, Me.Name, acSaveNo

Then close the VBE window, save the form (name it frmMsgBox or something
like that).

Now, when your macro opens this form, it will close automatically. Be sure
that you open the form using the Window Mode of Dialog.

--

Ken Snell
<MS ACCESS MVP>




dvonj said:
I have not been successful in figuring out how to do this. Could you
explain
the steps to make it happen. I read a lot of stuff in the MS help file but
nothing seems to work for me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top