Re: Running queries with a custom message box in Access 2007

Laura Mustto

New member
Local time
Today, 06:45
Joined
Jul 17, 2012
Messages
8
Re: Running queries with a custom message box in Access 2007

I been trying on my own but something doesn't work, please take a look at my code:

Private Sub Command121_Click()

If MsgBox("Do you wish to run query A and query B?", _
vbYesNo + vbQuestion, "Warning") = vbNo Then
End If

With DoCmd
.SetWarnings False
.OpenQuery "QueryA"
.SetWarnings True
End With
With DoCmd
.SetWarnings False
.OpenQuery "QueryB"
.SetWarnings True
End With
MsgBox "Both queries were successfuly executed", vbInformation

End Sub
 
Re: Running queries with a custom message box in Access 2007

hi Laura


When you say it does not work, what error messages are you getting?

You will always run both queries regardless of whether the user clicks yes or no because you have not handled both outcomes of the messagebox response (yes and no).

This would be better:
If MsgBox("Do you wish to run query A and query B?",vbYesNo + vbQuestion, "Warning") <> vbYes Then Exit Sub


I am just wondering why you double posted this?
 
Re: Running queries with a custom message box in Access 2007

I am just wondering why you double posted this?

Duplicate thread removed. This one is the only one now.
 
Re: Running queries with a custom message box in Access 2007

And the code should be:

Code:
Private Sub Command121_Click()

If MsgBox("Do you wish to run query A and query B?", _
vbYesNo + vbQuestion, "Warning") = vbYes Then

      With DoCmd
         .SetWarnings False
         .OpenQuery "QueryA"            
         .OpenQuery "QueryB"
         .SetWarnings True
      End With
      MsgBox "Both queries were successfuly executed", vbInformation
   End If
End Sub
 
Last edited:
Re: Running queries with a custom message box in Access 2007

And the code should be:

Code:
Private Sub Command121_Click()
 
If MsgBox("Do you wish to run query A and query B?", _
vbYesNo + vbQuestion, "Warning") = vbNo Then
 
      With DoCmd
         .SetWarnings False
         .OpenQuery "QueryA"            
         .OpenQuery "QueryB"
         .SetWarnings True
      End With
      MsgBox "Both queries were successfuly executed", vbInformation
   End If
End Sub

Err, Bob, shouldn't that be =vbYes otherwise the user has to answer no to run both queries.:eek::eek::eek:
 
Re: Running queries with a custom message box in Access 2007

Err, Bob, shouldn't that be =vbYes otherwise the user has to answer no to run both queries.:eek::eek::eek:

Oops, yes, I missed that part. :) I'll go modify it.
 
Re: Running queries with a custom message box in Access 2007

Hi guys, I messed up with the thread, my original post was completely different.

But it was basically about this code, trying and retrying I could fixed it myself, but the one you guys propose here looks simpler so I'll probably use it instead.

Thank you very much, nice forum!
 
Re: Running queries with a custom message box in Access 2007

Oh and one last question (out of curiosity) I understand the "Setwarnings False" (it turns action query messages off) but what's the point of the "setwarnings true" that comes afterwards?
 
Re: Running queries with a custom message box in Access 2007

It turns the system warning back on again:D

It is always a good idea to do this, so that Access can put up warnings at other times that may be needed. Without this your users could start changing things and not no it.
 

Users who are viewing this thread

Back
Top Bottom