Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 12th, 2003, 08:38 PM
Authorized User
 
Join Date: Jun 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default Open Print dialogue box

Hi,

Does anyone have a code or link to opening Print Dialogue Box in Access ? I'd like the users to be able to choose a printer before printing reports.

Thanks,

Vlad
__________________
Vlad
Sydney, Australia
 
Old October 12th, 2003, 10:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Vlad,

What version of Access are you using? I'm not exactly sure how to access the Window's Print Preview Dialog (nasty API calls and WIN.INI file reads probably).

But if you are running A2K or higher, and just want "users's to be able to choose a printer before printing reports", I can post some code to roll your own Print Preview Dialog that:

1. Lists all the reports in your app in a combo box.
2. Lists all the printers avalable on your system in a combo box.
3. Lets user's select the number of copies to be printed.
4. Lets user's select Portrait or Landscape orientation.
5. Previews the report.
6. Prints the report.

Thats about everything a user would really need anyway. You can do it all in less than 50 lines of code using the Application object's Printers Collection.

Let me know if you're interested.

Bob



 
Old October 12th, 2003, 10:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Oops...read Print Dialog anywhere I mentioned Print Preview Dialog above.

 
Old October 13th, 2003, 12:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Placing the following in the reports Activate event seems to get it. You could probably tweak it so that the report previews before it prints if you want:

Private Sub Report_Activate()
On Error GoTo Err_Report_Activate
    Dim strMsg As String
    Dim strTitle As String

    strMsg = "The Were No Records Returned." & vbCrLf & _
        "Print has been Canceled."
    strTitle = " No Records Returned"

    If Me.Report.HasData Then
        DoCmd.RunCommand acCmdPrint
        DoCmd.Close acReport, Me.Name
    Else
        MsgBox strMsg, vbInformation + vbOKOnly, strTitle
        DoCmd.Close acReport, Me.Name
    End If
Err_Report_Activate:
    Resume Next
    DoCmd.Close acReport, Me.Name

End Sub

Regards,

Bob

 
Old October 13th, 2003, 02:51 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Bob

The Printer object is only available in in XP - A2K still requires horrible API calls, etc.

The Access Developers Handbook (XP) version does have a wrapper class for these API calls, but I've never looked at it and even the authors seemed dubuious about it's utility!


Brian Skelton
Braxis Computer Services Ltd.
 
Old October 13th, 2003, 03:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Thanks Brian. Sorry to here that. I'm running Access XP these days and the Printer object sure does simplifiy things a lot. the code I posted for the Activate event will cause the Print Dialog to open when the report is run, at least in XP, though I'd suspect in earlier versions too. It's pretty straight forward. Could be kinda' handy.

Regards,

Bob

 
Old November 20th, 2003, 12:09 PM
Registered User
 
Join Date: Nov 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To get the Print Dialogue for Forms
Private Sub Form_Activate()
On Error GoTo Err_Form_Activate
    Dim strMsg As String
    Dim strTitle As String

    strMsg = "The Were No Records Returned." & vbCrLf & _
        "Print has been Canceled."
    strTitle = " No Records Returned"

    If Me.Form.HasData Then
        DoCmd.RunCommand acCmdPrint
        DoCmd.Close acForm, Me.Name
    Else
        MsgBox strMsg, vbInformation + vbOKOnly, strTitle
        DoCmd.Close acForm, Me.Name
    End If
Err_Report_Activate:
    Resume Next
    DoCmd.Close acForm, Me.Name

End Sub
 
Old September 21st, 2004, 08:46 AM
Registered User
 
Join Date: Sep 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you want to simply replace the Print button:

Make a Macro containing:

RunCommand

"Print"

Save, then link to the menu. If you want the Printer icon, copy it from the printer icon built into the "File" menu.

Works like a dream in Access 2000.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying Run Dialogue Box mr_kane VB.NET 10 November 27th, 2007 12:43 PM
How to open a dialogue box maximized Pete Bone Visual C++ 0 October 10th, 2007 06:23 AM
Open the "Open File" dialogue box piratelordx Access VBA 4 March 14th, 2006 10:08 PM
Closing an IE "OK" Dialogue box. Ahrenl Excel VBA 4 May 27th, 2005 10:04 AM
Print Dialogue for Forms per tab/page jaip2p Access VBA 1 November 20th, 2003 12:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.