Using MsgBox without pausing the application

2019-01-24 03:47发布

问题:

I need to display a message to the user. When I do this using MsgBox, the program stops until the user clicks the box away. I'd like to know if there's a way to open the MsgBox without pausing the program.

回答1:

Sounds like you're not expecting any user input from the MsgBox. In this case, depending on your application, the StatusBar may be an adequate substitute.

In Excel this is easy:

Application.StatusBar = "Please be patient..."
Application.StatusBar = iDone & " of " & iTotal & " items done."

To clear the StatusBar when done:

Application.StatusBar = False

In Access, the syntax is a tiny bit more convoluted:

Temp = SysCmd(acSysCmdSetStatus, "Hey, look at me!") ' Puts out your message
Temp = SysCmd(acSysCmdClearStatus) ' Clears StatusBar


回答2:

As far as I've ever been able to discover, the answer is you can't. The work-around is a custom form that serves as a dialog box.

See http://www.mvps.org/access/forms/frm0046.htm (not precisely your question, but applicable).



回答3:

MsgBox is modal (meaning the window comes up and halts execution of code until it is cleared). As other posters/commenters have mentioned - your alternative is to write your own version of a popup that is not modal. Not really worth the effort unless you really need it that way.



回答4:

Create a Form instead. I created a small form that only has a text box that says "Working, Please Wait". When needed I open the form, as a pop-up (docmd openform "form name"), usually just before starting some operation that is going to take some time to complete. When the work completes I close the form (docmd close acform "form name"). This does not stop the program but does provide a "Message" to the user.



回答5:

In the VB editor: Select Insert menu UserForm. In the Toolbox select TextBox: Drag a rectangle in the UserForm and type your text into it. Right click on the UserForm and select Properties. In the ShowModal property: Select False. In your VBA module enter UserForm1.Show where you want to turn it on and UserForm1.Hide where you want to turn it off. UserForm1 is mine, of course use the appropriate name for the form you created.



回答6:

I believe you first need to evaluate if you really need a msgbox to pops-up and keep you code running.

The msgbox functionality (as already stated) is modal and you cannot 'bypass' it. However, you can create a form (similar to the msgbox), set this form as 'not Modal' and call the code to show this form. The code workflow goes on. Tested and works in Excel.

Update: My Access has lost a reference, I won't be able to test it now. Hope it works in Access as well.

Rgds



回答7:

You can use WScript's Popup method. Here's the full details including sample code: http://msdn.microsoft.com/en-us/library/x83z1d9f%28v=vs.85%29.aspx