bring up print dialog from vba

I

icccapital

I have a working common dialog control on my development environment which is
vista and access 2007, but in the users runtime environment, with
comdlg32.dll registered on their machine. They get the error "no object
specified".

So I either need a way to get this to work on the user machine or a
different way to bring up the print dialog.


The reason for needing the print dialog is I need to have vba control the
printing of a couple hundred reports in a row, but to use the printer
selected by the user. Thanks for the help.
 
D

dymondjack

DoCmd.RunCommand acCmdPrint

This apparently works in access 97, though I'm not sure about future
versions, or how integrate it with what you are trying to do.

Daniel's second post in this thread has a link to some printing code... the
last post in the link he gives has some pretty in-depth opetions for printing
preferences from vba. I would think you should be able to use this with a
form to let the user select the desired printer.

http://www.microsoft.com/communitie...&p=1&tid=7bd3cfd2-802b-4fae-8799-272745d7d214

Here's the direct link
http://www.vbforums.com/showthread.php?t=494671

I saved this link because it seemed promising for printing related issues,
but I haven't tried anything out on it.


hth
--
Jack Leach
www.tristatemachine.com

- "Success is the ability to go from one failure to another with no loss of
enthusiasm." - Sir Winston Churchill
 
I

icccapital

Thanks Dymondjack that was very helpful

dymondjack said:
DoCmd.RunCommand acCmdPrint

This apparently works in access 97, though I'm not sure about future
versions, or how integrate it with what you are trying to do.

Daniel's second post in this thread has a link to some printing code... the
last post in the link he gives has some pretty in-depth opetions for printing
preferences from vba. I would think you should be able to use this with a
form to let the user select the desired printer.

http://www.microsoft.com/communitie...&p=1&tid=7bd3cfd2-802b-4fae-8799-272745d7d214

Here's the direct link
http://www.vbforums.com/showthread.php?t=494671

I saved this link because it seemed promising for printing related issues,
but I haven't tried anything out on it.


hth
--
Jack Leach
www.tristatemachine.com

- "Success is the ability to go from one failure to another with no loss of
enthusiasm." - Sir Winston Churchill
 
D

Dale Fye

Keep in mind that you will need to trap for the error that is generated when
the print dialog is cancelled. Here is a function I use as part of all of my
reports shortcut menus:

Public Function fnReportPrint()

Dim rpt As Report, strRptName As String
Dim strMsg As String
Dim intResponse As Integer, bPrint As Boolean

On Error GoTo fnPrintReportError

Set rpt = Reports(Reports.Count - 1)
strRptName = rpt.Name

bPrint = True

If rpt.Pages > 10 Then
strMsg = "This report contains " & rpt.Pages & " pages! " _
& vbCrLf & vbCrLf _
& "Print this report anyway?"
intResponse = MsgBox(strMsg, vbOKCancel, "Excessive pages")
If intResponse = vbCancel Then bPrint = False
End If

On Error GoTo PrintReportError
If bPrint Then
With rpt
Application.RunCommand acCmdPrint
End With
End If

Exit Function

PrintReportError:
If Err.Number = 2501 Then
'do nothing (print was cancelled)
Else
Msgbox "Error in fnReportPrint" & vbcrlf _
& Err.number & ", " & err.description
End If

End Function
 

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