Search code examples
ms-accessvbamessageboxms-access-2003

MS Access 2003 - Message Box: How can I answer "ok" automatically through code


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!


Solution

  • 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