 |
| 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
|
|
|
|

October 12th, 2003, 08:38 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

October 12th, 2003, 10:11 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
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
|
|

October 12th, 2003, 10:18 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
Oops...read Print Dialog anywhere I mentioned Print Preview Dialog above.
|
|

October 13th, 2003, 12:07 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
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
|
|

October 13th, 2003, 02:51 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

October 13th, 2003, 03:20 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
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
|
|

November 20th, 2003, 12:09 PM
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

September 21st, 2004, 08:46 AM
|
|
Registered User
|
|
Join Date: Sep 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |