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