Msg Box VBA Issue

G

Guest

I am using the following code:

Sub MBox()
Dim Config as Integer
Dim Ans As Integer
Config = vbYesNo + vbQuestion + vbDefaultButton2
Ans = MsgBox("Are you sure the correct Axiom reports are open in Excel?",
Config)
If Ans = vbYes Then RunReport
Then I have the report code
End Sub

Everything is just fine and dandy - the box pops up with yes and no - but
when I click Yes nothing happens. When I click No, the report runs for
however many times I clicked Yes. It is very strange. Any suggestions on how
to get this to work properly?

Charles
 
B

Bob Phillips

Works as expected for me.

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)
 
B

Bob Phillips

I just copied your code.

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)
 
S

Susan

charles......
i have had horrible trouble using msgboxes in this configuration.
somebody here taught me to use them in an "if" statement, & i find (for
me) they work much better.
i would ammend your code as follows:

Sub MBox()
If MsgBox("Are you sure the correct Axiom reports are open in Excel?" _
, vbYesNo + vbQuestion) = vbYes Then
run report
end if
' Then I have the report code
End Sub


watch the google line wrapping - that underscore belongs up with the
previous line.
susan
 
G

Guest

Ok, using the IF statement works a lot better and at least the report runs
when I hit yes. However, when I hit no the report continues to run. How do I
just get the report to stop running when I hit no and to run when I hit yes.

Charles
 
S

Susan

If MsgBox("Are you sure the correct Axiom reports are open in Excel?" _else
exit sub 'or whatever else you want it to do
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top