non modal message box API that does not cause vba program to pause (without using a Userform)

My outlook mailEx program runs when Outlook does a send/receive. The program occasionally displays informational messages that I want the user to see. But, I don't want the messages to stop MailEx processing.

I solved this completely with a subroutine that displays a non-modal form.  In MailEx I simply code
       line33: call msgfastbox("line33","This message will stay on screen")
                    debug.print "But the program will continue to run"

I want to extend the this idea to Excel and Access, so I wonder if there is an API that does something similar but doesn't require a userform.  

I have googled for a while and I and found some web pages that say "NO THERE IS NO SUCH API". So, please,  don't point me to a potential solution, unless you are really sure  that it will run non-modally.  

For instance someone suggested I use "declare function myfunc Lib "User32" Alias "MessageBoxA"".   Perhaps I used it wrong but the last line of code at http://www.tek-tips.com/faqs.cfm?fid=4699 WAITS for the user to click OK. I tried variations, but they all waited for user response.

In case you are interested, here is the Outlook code that I am currently using. It does exactly what I want. It displays a non-modal message  box then continues executing the main program.


Sub msgFastBox(id As String, ByVal Text As String, Optional MilliSeconds)
' displays message non-modally for a few seconds.
'
' if no seconds are specified, the box will remain open until it is dismissed
' or until another msgFastBox is requested
Call writelogfile(id, Text)
frmMsgFastBox.Text.MultiLine = True
frmMsgFastBox.Text = Format$(Date, "MM/DD/YYYY") & " " & Format$(time(), "HH:MM:SS") & id & " " & Text
frmMsgFastBox.Show False
DoEvents
If Not IsMissing(MilliSeconds) Then
    Sleep MilliSeconds
    Unload frmMsgFastBox
End If
End Sub

Open in new window

LVL 5
rberkeConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
You would use the CreateDialog API call:

http://msdn.microsoft.com/en-us/library/ms644996%28v=VS.85%29.aspx#modeless_box

 But really, this is nothing more then creating a message box form on the fly.

I'd keep things simple and just create the forms in Excel/Access to accomplish this.

Jim.
0
Dale FyeCommented:
I have a popup form that I use for this.  It is just a small form (frmMsg) with two controls (lbl_message, and cmd_Continue).  The code behind the form has a public subroutine (Start) which I call to open the form, populate the comment and set the TimerInterval.

See attached.

From the immediate window (or your code), you can open the form with a line like:

form_frmMsg.start "message", 5

This will display "message" for 5 seconds, then automatically close the form. Or, the user can click the continue button to close the form.
MessageForm.accdb
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rberkeConsultantAuthor Commented:
Jim, That links needs to be translated to vba before I can understand it  

fyed: your solution is virtually identical to the solution I described in my first post.  I will give you a few points mainly because you saved me the trouble of translating my solution into access.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<fyed: your solution is virtually identical to the solution I described in my first post.>>

 For another alternative, see attached.

<<Jim, That links needs to be translated to vba before I can understand it >>

 It's not something that would translate to VBA.  You'd need to create the dialog template with API calls, then call CreateDialog().  That would all be with API's except for the calls themselves to the API's.

 Reason Dale and I have things we use like we have posted; it's simpler and easier to manage.

Jim.
ProgressBar.zip
0
rberkeConsultantAuthor Commented:
The progress bar implementations you folks have posted are equivalent to the userform solution that I previously developed for Outlook.  

But, since there is no neatly packaged API, I will give points for those contributions.

By the way, I came up with the following approach which works in in every MS Office environment.

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub test()
Call modelessMsgbox("ugly but it works")
End Sub
Sub modelessMsgbox(text)

' First create program ModelessMsg.vbs in c:\aaatmp\
'          Set objargsinall = WScript.Arguments
'          If WScript.Arguments.Count = 0 Then
'              MsgBox "ModelessMsg.vbs not called properly: no message passed"
'          Else
'              WScript.echo objargsinall(0)
'          End If
Set wShell = CreateObject("wscript.shell")
wshCommand = "taskkill /IM wscript.EXE /F" ' there must be a way, but this makes sure there is only one such msgbox displaying
wShell.Run wshCommand
Sleep 500
wShell.Run "wscript c:\aaatmp\test.vbs " & Chr(34) & Replace(text, Chr(34), "'") & Chr(34)

End Sub

Open in new window

0
rberkeConsultantAuthor Commented:
I should point out that my initially posted vba code had an optional interval timer.
If I used a 5 second timer, the message would not continue until the 5 seconds expired even if the user dismissed it.  

I don't think the alternatives posted by the experts have that problem, so they are "better" solutions.
0
rberkeConsultantAuthor Commented:
I improved my previous solution to allow an optional timeout parameter.
Option Explicit


Sub test()
Call modelessMsgbox("ugly but it works", 2)
End Sub
Sub modelessMsgbox(text, Optional timeout As Long = 5)
' Example: Call modelessMsgbox("This informational message does not stop vba".10)
'        the message will be displayed for 10 seconds.
'        if only 1 parameter is given, the message will display for 5 seconds
'
'
' For details, see:  <<  https://www.experts-exchange.com/questions/27992241/non-modal-message-box-API-that-does-not-cause-vba-program-to-pause-without-using-a-Userform.html  >>
' FIRST, Create the following script "c:\efgmdl\modelessMsg.vbs" (drop the leading quote)
     '    Set objargsinall = WScript.Arguments
     '    Set objshell = WScript.CreateObject("WScript.Shell")
     '    If WScript.Arguments.count = 0 Then
     '        objshell.popup "ModelessMsg.vbs not called properly: no message passed", 5
     '    ElseIf WScript.Arguments.count = 1 Then
     '        objshell.popup "1" & objargsinall(0), 5
     '    ElseIf WScript.Arguments.count > 1 Then
     '        objshell.popup objargsinall(0), objargsinall(1)
     '    End If
Dim wshell As Object
Set wshell = CreateObject("wscript.shell")
wshell.Run "wscript c:\efgmdl\modelessmsg.vbs " & chr(34) & Replace(text, chr(34), "'") & chr(34) & " " & timeout

End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.