views:

380

answers:

2

So a couple silly questions:

If I include this in some event:

MsgBox " ", vbOkOnly, "This little message box"

could I then with some more code turn around and 'click the ok button. So that basically the message boox automatically pops up, and then automatically goes away?

I know its silly because you want to know, why do you want the message box then.....

well a) i just want to know if you can do that, and what would be the command

b) i have some basic shapes (shape objects) that are made visible when the message box appears. But without having the message box there, there is no temporary disruption of code while waiting for the button to be clicked, and therefor those pretty image objects being made visible does take effect on the the form.

So I really do not need the message box, just the temp disruption that shows the objects.

Thanks!

+3  A: 

A MsgBox is Modal. There are only two Modality related settings

  • ApplicationModal
  • SystemModal

So if the Msgbox is popped up by your current application, no code will run until you click a button on the message box.

The way to get around this is to design your own message box using a form. You can pop this up and keep it on and then you can "click" any button you want on it.

If you want a delay, you can use the Win API to sleep

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub ApiSleep(SleepMilliseconds as Long)
    Sleep SleepMilliseconds 
End Sub
Raj More
A: 
Sendkeys "~",false

Should dismiss the msgbox (assuming it has focus)

I think you're looking for the paint events, or forcing a form refresh though to achieve what you actually want to do!

Edit: Ah damn, yeah, because it's modal the code is suspended... d'oh! As suggested, either write your own, or you'd have to throw something in another thread to do it, and I have no idea how to do multi threading in MS Access!

Second Edit: Have you looked at Application.Echo False to suspend and Application.Echo True to resume painting layout?

Doogie
Sendkeys should be avoided and does not work with Vista.
Remou
+1 thanks, hadn't heard about Sendkeys not working in Vista! It's been a long time since I developed anything inside Access!
Doogie
This won't work after a MsgBox statement because the code pauses on it and won't ever move to the SendKeys statement until the MsgBox is dismissed.
David-W-Fenton
In addition to the Application.Echo, there's also DoEvents which can allow screen painting to happen in an appropriate order where otherwise it might not. That includes painting things that aren't seen without it and hiding things that don't get hidden without it.
David-W-Fenton