Close currently opened MsgBox using code

2019-07-02 09:58发布

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

8条回答
疯言疯语
2楼-- · 2019-07-02 10:29

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.

查看更多
再贱就再见
3楼-- · 2019-07-02 10:29

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

查看更多
男人必须洒脱
4楼-- · 2019-07-02 10:39

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).

查看更多
劳资没心,怎么记你
5楼-- · 2019-07-02 10:40

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...

查看更多
再贱就再见
6楼-- · 2019-07-02 10:45

I used to have an easy answer to this: use the Windows Scripting Shell object, which has a 'Popup' function - a Message Box, just like the VBA MsgBox() function, with a 'SecondsToWait' parameter that provides exactly the timeout you wanted.

With CreateObject("Scripting.WsShell")
    .Popup "Watch me disappear in 5 seconds", 5, Application.Name & ": test", vbInformation + vbOkCancel
End With

If you include a 'Cancel' button, it might still work: the available parameters are vbOkCancel, vbYesNoCancel, and vbRetryCancel.

If you're trying to close a dialog box you didn't initiate with your own msgBox() function call, that's unhelpful: and, as I've hinted above, the 'SecondsToWait' parameter doesn't really work these days - someone in Redmond really does't like the idea of one thread closing another thread's helpful warnings and important interruptions to the user's workflow.

However, you can launch a delayed Message Box 'Close' command using the API Timer() function - not quite 'close the currently opened MsgBox', as this requires advance warning that you intended to open it - but it's the closest thing I have, it fits into a self-contained VBA module, and I posted the code in an answer to a very similar StackOverflow question to yours.

I should warn you that the answer in question is using a sledgehammer to crack a nut, with a side order of lengthy explanation.

查看更多
倾城 Initia
7楼-- · 2019-07-02 10:50

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

查看更多
登录 后发表回答