views:

821

answers:

8

Is there any option to close the currently opened MsgBox using any code in VBA access form application ? \

+1  A: 

I may be wrong but MsgBox is a blocking call creating a modal form so I don't think there is an easy way such as an option to do that. Do you have a specific use case for this ?

Sébastien Nussbaumer
i dont know where the message box is poping , i dont want to analyse where it comes from insted i want to KILLLLLL :-)
If you want to know where the message box is poping, just hit "Ctrl + Break" to see what's causing that and comment the call. If it's a third party dll poping the box, then unless there is some property to make it "silent" you're probably not going to be able to do anything
Sébastien Nussbaumer
It could also be an Access native MsgBox triggered by something you've done. If so, there might be an alternative way to make Access "silent"
MarkJ
+3  A: 

Check out Randy Birch's response on this thread in microsoft.public.vb.general.discussion

He recommends creating a function in a .bas file called MsgBox. Doing so will cause VB to call your function rather than the built in one.

You'd then create your own MsgBox form and build in a timer to close your form after a set period of time. He provides links showing how to do this.

He also discusses a way to explicitly call the built in MsgBox function in case you need to do this.

Note: I've never done this but I've found that Randy Birch is a knowledgeable resource.

Jay Riggs
This will only work if the MsgBox is being displayed from your own code. If it is an Access native MsgBox, you will need another approach.
MarkJ
You can hook another app's msgbox from your app and close it. You will find out about hooks and msgbox's from the resource above. I have had to do it 1000 times and spent a few weeks living on his site. :) Avoid sendkeys like the plague. With a user on the system it is undepenable at the very least as to which app will end up getting the keystroke.
Praesagus
+1  A: 

MsgBoxes are not intended to be programmatically closed, that's why it's difficult to do so. If you find yourself in a design where you must force close a MsgBox, you should probably re-evaluate your design.

Rob Elliott
A: 

Rather than writing an alternative to the Access MsgBox from scratch, you might consider using (or at least studying) Arvin Meyer's Custom MessageBox Creator (downloadable on this page).

David-W-Fenton
+1  A: 

As MarkJ points out, could this could be a dialog generated by Access (rather than a VBA.MsgBox called in your own code)?

For example, when using table's 'dataview' in the Access UI to add a row you get a message, "You are about to append 1 record..." (or similar). Is this the kind of message you mean? If so, there are indeed ways to suppress them...

onedaywhen
A: 

I have similar problem and theoretically you can use "SendKeys" function (see http://msdn.microsoft.com/en-us/library/8c6yea83%28VS.85%29.aspx). However, the MsgBox blocks the running so you cannot use the command. If you know when It going to pop up, you may run (from the script) external whshell that wait some time and then use the SendKeys. But if you know how to do that, tell me (here). Other similar possibility is to open different thread/process for it that will not be block, but I don't know if it is possible in VBA.

Oded

A: 

Hi,

Message Boxes are ment to depict some information to the user. Hence programatically closing is not a good design, unless you are not automatings some process.

You can use sendkeys or win APIs.

Thanks, pkrg

A: 

I have similar problem, There is an application that pop up a query window that I know what should be clicked to close it and theoretically can manage it using SendKeys. However, the pop up window (that popped up as a result of a command I myself run (cannot avoid of it)) is blocking the continuous of the running, so I can't use sendkeys from the main stream. Is there a way to use the sendkeys, like other thread/process ? How ??? (I can't overtake the call to the routine that pops the window up, I don't have the code behind it and I need the side effect of this window) :-(

Oded