By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,474 Members | 3,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,474 IT Pros & Developers. It's quick & easy.

Is it possible to programmatically close a MsgBox?

P: n/a
Can I close a MsgBox with VBA Code? Something like:

If IsOpen (MsgBox, "Title") Then
Close(MsgBox, "Title")
Run some code
Else
Run other code
End If

Can this be done in VBA? Do I need to work with an API function?

Thanks in advance.
Nov 12 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
No, because the message box is "modal" and stops code execution. It is
almost trivially easy to create your own form that works similar to a
message box, but has a timer, and can close itself.

Larry Linson
Microsoft Access MVP

"deko" <de**@hotmail.com> wrote in message
news:FL******************@newssvr27.news.prodigy.c om...
Can I close a MsgBox with VBA Code? Something like:

If IsOpen (MsgBox, "Title") Then
Close(MsgBox, "Title")
Run some code
Else
Run other code
End If

Can this be done in VBA? Do I need to work with an API function?

Thanks in advance.

Nov 12 '05 #2

P: n/a
> No, because the message box is "modal" and stops code execution. It is
almost trivially easy to create your own form that works similar to a
message box, but has a timer, and can close itself.


10-4 - I created my own form and it works fine. Thanks for the tip.
Nov 12 '05 #3

P: n/a
deko wrote:
Can I close a MsgBox with VBA Code? Something like:

If IsOpen (MsgBox, "Title") Then
Close(MsgBox, "Title")
Run some code
Else
Run other code
End If

Can this be done in VBA?


Actually, yes. I put a command button on a form that when pressed will
display a message box. The message box will be closed in 5 seconds.

Option Compare Database
Option Explicit
Private Sub Command0_Click()
Me.TimerInterval = 5000
MsgBox "Hello. I will go bye-bye in 5 seconds."
Me.TimerInterval = 0
End Sub
Private Sub Form_Timer()
'you could use "{Esc}" here
SendKeys "{Enter}"
End Sub
What about a multiple button msgbox?

Option Compare Database
Option Explicit
Private Sub Command0_Click()
Dim var As Variant
Me.TimerInterval = 5000
'if nothing is pressed on multiple button msgboxes
'then default button is selected. You can get around
'this with a flag setting...ex in OnTimer set a flag
'to true (or false) that determines if Timer closed
'the msgbox or if the user did.
var = MsgBox("Hello", vbYesNo, "Hi")
Me.TimerInterval = 0
MsgBox (var = vbYes)
End Sub
Private Sub Form_Timer()
'can't use "{Esc}" with multiple button options
SendKeys "{Enter}"
End Sub

Nov 12 '05 #4

P: n/a
Salad <oi*@vinegar.com> wrote in news:UGggc.14973$k05.3379
@newsread2.news.pas.earthlink.net:
deko wrote:
Can I close a MsgBox with VBA Code? Something like:

If IsOpen (MsgBox, "Title") Then
Close(MsgBox, "Title")
Run some code
Else
Run other code
End If

Can this be done in VBA?


Actually, yes. I put a command button on a form that when pressed will
display a message box. The message box will be closed in 5 seconds.

Option Compare Database
Option Explicit
Private Sub Command0_Click()
Me.TimerInterval = 5000
MsgBox "Hello. I will go bye-bye in 5 seconds."
Me.TimerInterval = 0
End Sub
Private Sub Form_Timer()
'you could use "{Esc}" here
SendKeys "{Enter}"
End Sub
What about a multiple button msgbox?

Option Compare Database
Option Explicit
Private Sub Command0_Click()
Dim var As Variant
Me.TimerInterval = 5000
'if nothing is pressed on multiple button msgboxes
'then default button is selected. You can get around
'this with a flag setting...ex in OnTimer set a flag
'to true (or false) that determines if Timer closed
'the msgbox or if the user did.
var = MsgBox("Hello", vbYesNo, "Hi")
Me.TimerInterval = 0
MsgBox (var = vbYes)
End Sub
Private Sub Form_Timer()
'can't use "{Esc}" with multiple button options
SendKeys "{Enter}"
End Sub


sigh ...

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #5

P: n/a
Lyle Fairfield wrote:
Salad <oi*@vinegar.com> wrote in news:UGggc.14973$k05.3379
@newsread2.news.pas.earthlink.net:

deko wrote:

Can I close a MsgBox with VBA Code? Something like:

If IsOpen (MsgBox, "Title") Then
Close(MsgBox, "Title")
Run some code
Else
Run other code
End If

Can this be done in VBA?


Actually, yes. I put a command button on a form that when pressed will
display a message box. The message box will be closed in 5 seconds.

Option Compare Database
Option Explicit
Private Sub Command0_Click()
Me.TimerInterval = 5000
MsgBox "Hello. I will go bye-bye in 5 seconds."
Me.TimerInterval = 0
End Sub
Private Sub Form_Timer()
'you could use "{Esc}" here
SendKeys "{Enter}"
End Sub
What about a multiple button msgbox?

Option Compare Database
Option Explicit
Private Sub Command0_Click()
Dim var As Variant
Me.TimerInterval = 5000
'if nothing is pressed on multiple button msgboxes
'then default button is selected. You can get around
'this with a flag setting...ex in OnTimer set a flag
'to true (or false) that determines if Timer closed
'the msgbox or if the user did.
var = MsgBox("Hello", vbYesNo, "Hi")
Me.TimerInterval = 0
MsgBox (var = vbYes)
End Sub
Private Sub Form_Timer()
'can't use "{Esc}" with multiple button options
SendKeys "{Enter}"
End Sub

sigh ...


Why sigh?

Nov 12 '05 #6

P: n/a
Salad wrote:
Lyle Fairfield wrote:
Salad <oi*@vinegar.com> wrote in news:UGggc.14973$k05.3379
@newsread2.news.pas.earthlink.net:

deko wrote:
Can I close a MsgBox with VBA Code? Something like:

If IsOpen (MsgBox, "Title") Then
Close(MsgBox, "Title")
Run some code
Else
Run other code
End If

Can this be done in VBA?
Actually, yes. I put a command button on a form that when pressed
will display a message box. The message box will be closed in 5
seconds.

Option Compare Database
Option Explicit
Private Sub Command0_Click()
Me.TimerInterval = 5000
MsgBox "Hello. I will go bye-bye in 5 seconds."
Me.TimerInterval = 0
End Sub
Private Sub Form_Timer()
'you could use "{Esc}" here SendKeys "{Enter}"
End Sub
What about a multiple button msgbox?

Option Compare Database
Option Explicit
Private Sub Command0_Click()
Dim var As Variant
Me.TimerInterval = 5000
'if nothing is pressed on multiple button msgboxes
'then default button is selected. You can get around
'this with a flag setting...ex in OnTimer set a flag
'to true (or false) that determines if Timer closed
'the msgbox or if the user did.
var = MsgBox("Hello", vbYesNo, "Hi")
Me.TimerInterval = 0
MsgBox (var = vbYes)
End Sub
Private Sub Form_Timer()
'can't use "{Esc}" with multiple button options
SendKeys "{Enter}"
End Sub


sigh ...

Why sigh?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

SendKeys, bad joojoo.

When the MsgBox is open the user can set the focus on another
application. What if the SendKeys occurs when the focus is on a Format
dialog box and the focus is on the "Do you really want to do this"
button and the drive to be formatted is C:? Time elapses SendKeys sends
{Enter} & format commences. Yikes!

I know far-fetched, but you know users - unpredictable creatures: "Hey,
I wonder what this does?".
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQIQ1tYechKqOuFEgEQKxUgCeJThrwV+AJ6+bvesToBx1r9 ID7PEAnjyE
BHNQR94g0yODzCSrqfG3r1eg
=WTwr
-----END PGP SIGNATURE-----

Nov 12 '05 #7

P: n/a
MGFoster wrote:
SendKeys, bad joojoo.

When the MsgBox is open the user can set the focus on another
application. What if the SendKeys occurs when the focus is on a Format
dialog box and the focus is on the "Do you really want to do this"
button and the drive to be formatted is C:? Time elapses SendKeys sends
{Enter} & format commences. Yikes!
LOL
I know far-fetched, but you know users - unpredictable creatures: "Hey,
I wonder what this does?".


They ask questions for trivial matters but never ask during crucial matters.

Thanks for the update. I don't think I have any users that are as swift
as the ones you describe up above <g>

Nov 12 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.