Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-01-11
7
Medium Priority
?
2,577 Views
Last Modified: 2017-06-04
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

0
Comment
Question by:rberke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 58
ID: 38766771
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
 
LVL 48

Accepted Solution

by:
Dale Fye earned 1000 total points
ID: 38767111
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
 
LVL 5

Author Comment

by:rberke
ID: 38769307
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 58

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 1000 total points
ID: 38774296
<<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
 
LVL 5

Author Comment

by:rberke
ID: 38781775
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
 
LVL 5

Author Comment

by:rberke
ID: 38781861
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
 
LVL 5

Author Comment

by:rberke
ID: 42161904
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question