Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically Close MsgBox 2

Status
Not open for further replies.

Mungovan

Programmer
Oct 24, 2002
94
IE
Hi.
I need a message box to appear on the screen for 1-2 seconds and then automatically close itself without the user having to press anything.

Is this possible??

Thanks
 
I am not sure if this is possible with the standard VB message box function.

However you can always create your own form and place a timer on it.

Thanks and Good Luck!

zemp
 
I can't imagine how you would do that. You can only satisfy a msgbox by clicking one of its buttons, but you can't send a click event to them, because you do not have access to the buttons as objects. You could maybe use a timer in one form to Unload the form that has the msgbox, but that is serious overkill, and I mention it as purely academic conjecture. I must agree with zemp. Create a form that looks like a message box, but do not use "msgbox." It is too restrictive.
 
You can try this MsgboxTimeout function in conjunction with a timer to do this job.

Place a command button (Command1) and a timer (Timer1) on your form containing the following code. Run and test the program to see the message box vanish automatically.
___

Option Explicit
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long

Private Sub Command1_Click()
Debug.Print MsgboxTimeout("This message box will automatically dismiss in 5 seconds!", vbExclamation, "Message box with timeout", 5000)
End Sub

Function MsgboxTimeout(Prompt As String, Optional Buttons As VbMsgBoxStyle, Optional Title As String, Optional TimeoutMilliSeconds As Long) As VbMsgBoxResult
If Title = vbNullString Then Title = App.Title
Timer1.Tag = Title
Timer1.Interval = TimeoutMilliSeconds
Timer1.Enabled = True
MsgboxTimeout = MessageBox(hwnd, Prompt, Title & Chr$(160), Buttons)
If Timer1.Tag = vbNullString Then MsgboxTimeout = 0 'indicates a timeout dismissal
Timer1.Enabled = False
End Function

Private Sub Timer1_Timer()
AppActivate Timer1.Tag & Chr$(160)
Timer1.Tag = vbNullString
SendKeys " "
End Sub
 
very nice!!! * for u

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
The Great Date Debate Thread222-368305
File Formats Galore @ or
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top