You are here:

Using MS Access/Can MsgBox "OK" control actions?


Hi Scott

I have some code which finishes off with a confirmation MsgBox, and was wondering if it's possible to force more code when the [OK] is clicked?

This is the code:

   DoCmd.Close acForm, "FrmSeedings", acSaveYes
   MsgBox "Round Robin Groups set and saved!"
   DoCmd.OpenForm "FrmRoundRobin"

As you would realise, the form "FrmRoundRobin" appears and hides the MsgBox from being clicked as [OK] !

Is there a workaround to make "FrmSeedings" close, make the MsgBox stay visible, and then when [OK] is clicked, open "FrmRoundRobin"?  So probably a way to pause execution of the next line of code until MsgBox hs been answered?

It's probably simple, but I ahve had a hard day at work, and my body says rest but my mind won't give up!  lol

many thanks in anticipation


Sure, Use the MsgBox FUNCTION instead of just the command. The difference is that the parameters go in parentheses so they return a value.

However, that's not your completely your issue. The MsgBox should retain focus until pressed, But sometimes it does hide so try this.

First try this way:

  MsgBox "Round Robin Groups set and saved!"
  DoCmd.OpenForm "FrmRoundRobin"
  DoCmd.Close acForm, "FrmSeedings", acSaveYes

You shouldn't close the current form until after you run all other lines of code. If that doesn't solve the problem, then try it this way:

  If MsgBox("Round Robin Groups set and saved!",vbOKCancel) = vbOK Then
       DoCmd.OpenForm "FrmRoundRobin"
  End If
  DoCmd.Close acForm, "FrmSeedings", acSaveYes

Hope this helps,
Microsoft Access MVP 2007
Author: Microsoft Office Access 2007 VBA

Using MS Access

All Answers

Answers by Expert:

Ask Experts




I can answer almost all types of questions relating to Microsoft Access usage and application design. My strengths are database and interface design.


I've been designing databases for over 25 years working with dBase, FoxPro, Approach and Access.

Author of Microsoft Office Access 2007 VBA
Techncial Editor for Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports & Queries From Que Publishing

Brooklyn College BA

©2016 All rights reserved.