MS Access - VBA - Multiple tasks with one button

I am trying to build a customer interface for ease of use using a form...

Private Sub Label21_Click()
Dim Answer As Integer
Answer = MsgBox("Print  Report 1", vbYesNo)
    If Answer = vbYes Then
    DoCmd.OpenReport "Report 1", acPreview
    End If

'  when I answer yes, the report comes up for viewing before printing '
'   as you are aware, the next message box comes up before I have previewed the current screen '
'  do I need to write some kind of do-loop to monitor when I close the preview window before it ask me the next question? '
'  if that is a possible or best solution,  how do I find out what that window is called ? '
'  I was also thinking it would be nice to have another message box come up to confirm printing after viewing or cancel '

Answer = MsgBox("Print Report 2", vbYesNo)
    If Answer = vbYes Then
    DoCmd.OpenReport "Report 2", acPreview
    End If

End Sub

tnx's b2
bruceblackmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kmcbreartyCommented:
Use

DoCmd.OpenReport "Report Name", acViewPreview, , , acDialog

Instead of

DoCmd.OpenReport "Report Name", acViewPreview

This will stop the code from running until the preview window is closed.

Kevin
0
kmcbreartyCommented:
I am sorry I didn't read the second part of your question.

If you would like a second message box to confirm if the user wants to print the report after previewing it.  Use the Following:

Note:  I added a title to this code, I wasn't sure if you knew you could add a title to the message box or not.  If you don't want to use a title just omit the ( , "Title" ) from the code.
____________________________________________________________________________________________________

Answer = MsgBox "Would you like to print the report", vbYesNo, "Title"

  If Answer = vbYes Then
      DoCmd.OpenReport "ReportName",  acViewNormal
  End If
____________________________________________________________________________________________________

This will print to the report to the default printer.

Kevin

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bruceblackmanAuthor Commented:
I would like to try before I accept..... It is past my bedtime tonight.  There is soooo much to learn and always a challenge  to decide what to read!  It reads like the correct solution and thank you for the additional code.  Adding VBA to access is really helping useability for customer interface...

tnx's b2
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

kmcbreartyCommented:
Not a problem.  I wouldn't want you to accept it if it doesn't work for you.  Let me know if you need anything else.

Kevin
0
harfangCommented:
I think that WindowMode:=acDialog only exists for forms, not reports.
Hence, I see no way to stop the second MsgBox to appear using a single VB function.

The only way to go would be to use the first report's On Close event to ask the user if he wants the second report to be previewed.

As for asking if the user wants to print when he closes the report, I think it's rude. There is a print button and a close button. If I click "Close", I normally do not expect a Microsoft-like "are you sure you don't want to print now?" message. At least, be certain to record the fact that the user *has* in fact just printed the report, so as not to ask stupid questions :)
(You can also use the close event to do this if you insist...)

Cheers!
0
kmcbreartyCommented:
harfang,

I respectfully disagree.  I looked before I posted it.  Like you I I wasn't sure if this was an option when opening reports, so I checked to make sure.

Kevin
0
harfangCommented:
Kevin, sorry I doubted you. You are indeed right, the parameter has been added with Access 2002.
My mistake, old habits die hard... :)
Cheers:)
0
bruceblackmanAuthor Commented:
It works...  Of course I expected it to work when I am working with experts!!! Thank you Kevin.. Also thiank you for the title bar in the message box.... That adds a nice touch....

As to harfang's words about being rude....  I respect his concern and follow his thinking but I found after viewing the report I can only close so I need the next message window to ask the question "do you want to print".  I also reworded by first message to ask if they wanted to view the report.  While viewing, my print icon is not available or is the file print pull down menu....

Expert exchange is a great database for learning - please keep up the good work Kevin & harfang

tnx's b2
0
harfangCommented:
> "While viewing, my print icon is not available"
Well, I think it should be. If you use custom toolbars, consider adding it. If you are using MDE format on a runtime environment, you should create your own custom toolbars anyways.

Cheers :)
0
agarillonCommented:
I ran across a problem passing arguments and figured out the problem with OpenArgs.

It seems passing args only works properly with acViewPreview... so to print you call it twice, once with acViewPreview,second with acViewNormal

Anything else seems to make args = Null when trying to set them from inside the report.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.