[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MS Access - VBA - Multiple tasks with one button

Posted on 2004-11-30
10
Medium Priority
?
315 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:bruceblackman
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Expert Comment

by:kmcbrearty
ID: 12712558
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
 
LVL 3

Accepted Solution

by:
kmcbrearty earned 400 total points
ID: 12712592
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
 

Author Comment

by:bruceblackman
ID: 12712832
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Expert Comment

by:kmcbrearty
ID: 12712911
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
 
LVL 58

Expert Comment

by:harfang
ID: 12713026
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
 
LVL 3

Expert Comment

by:kmcbrearty
ID: 12713431
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
 
LVL 58

Expert Comment

by:harfang
ID: 12713539
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
 

Author Comment

by:bruceblackman
ID: 12718808
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
 
LVL 58

Expert Comment

by:harfang
ID: 12719466
> "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
 
LVL 1

Expert Comment

by:agarillon
ID: 21285488
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question