473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Is it possible to programmatically close a MsgBox?

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
7 110290
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
> 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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: deko | last post by:
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...
3
by: Ronny Sigo | last post by:
Hello all, I have made a button in access which opens iexplore and directs it to a certain website. I have use a piece of code written by Dev Ashish. So far so good. But now I need to know how I...
4
by: Pierke | last post by:
Hey guys out there, I really need your help, i am building up a web site, so for security reasons i need to do "some things" before the user log off, and i indeed do it. Now the matter is that...
7
by: mg | last post by:
Once opening WebForm2 from WebForm1 using Response.Write("<script language='javascript'>window.open ('WebForm2.aspx','two','menubar=no');</script>"); how can I close WebForm1?
2
by: Bruce Wiebe | last post by:
hi all im having a problem accessing a text file on my hard disk after ive created it and added some text to it it would appear that the file is still locked. What happens is this i have...
3
by: Valerie Hough | last post by:
I would like to be able to determine if a given folder is open on a user's desktop, and be able to close it. Is this possible? Thanks in advance, Valerie Hough
6
by: Frank Rizzo | last post by:
I am trying to programmatically close a messagebox. I don't see any obvious managed choices. Back in the day, I remember using a combination of FindWindow and EndDialog apis(...
1
by: dummy07 | last post by:
Is it possible to close a modal window from the parent window??? Please help..
1
by: sneha9 | last post by:
hi all, Please let me know if we can close the dialogbox opened by some other program on windows, i mean if am putting automation scripts for run and inbetween if the program fails due to some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.