I have set a form up that reads all of the printers available on my network and puts them into a list box. Then the user selects the printer they want to print to and clicks the print button.
The idea is to allow me to test if someone is printing to a pdf file and if they are, asking them if they want to add the company logos to the form they are trying to print. The reason the logos have to be imported is that if the form is printed normally it will go on headed paper.
The code below will show via a message box a change in printer devicename but when you print it actually does not change to the printer selected.
Any help much appreciated.
Steve
Private Sub btnPrintForm_Click()
On Error GoTo Err_btnPrintForm_Click
Dim stDocName As String
Dim MyForm As Form
'PS= Printer Selected
Dim PS As String
PS = Me.txtSelectedPrinter
'Ask if EFR logos and banner to be inserted as
'printing to pdf
If PS = "Acrobat Distiller" Or _
PS = "FinePrint pdfFactory pro" Then
BandL.B_L_Insert
End If
stDocName = Me.txtFormNameToPrint
Set MyForm = Screen.ActiveForm
DoCmd.SelectObject acForm, stDocName, True
'change printer to selected
Set Application.Printer = Application.Printers(PS)
MsgBox& Application.Printer.DeviceName
'DoCmd.PrintOut acPrintAll, , , , Me.txtNoOfCopies
DoCmd.SelectObject acForm, MyForm.Name, False
BandL.B_L_Remove
Exit_btnPrintForm_Click:
Exit Sub
Err_btnPrintForm_Click:
MsgBox Err.Description
Resume Exit_btnPrintForm_Click
End Sub
The idea is to allow me to test if someone is printing to a pdf file and if they are, asking them if they want to add the company logos to the form they are trying to print. The reason the logos have to be imported is that if the form is printed normally it will go on headed paper.
The code below will show via a message box a change in printer devicename but when you print it actually does not change to the printer selected.
Any help much appreciated.
Steve
Private Sub btnPrintForm_Click()
On Error GoTo Err_btnPrintForm_Click
Dim stDocName As String
Dim MyForm As Form
'PS= Printer Selected
Dim PS As String
PS = Me.txtSelectedPrinter
'Ask if EFR logos and banner to be inserted as
'printing to pdf
If PS = "Acrobat Distiller" Or _
PS = "FinePrint pdfFactory pro" Then
BandL.B_L_Insert
End If
stDocName = Me.txtFormNameToPrint
Set MyForm = Screen.ActiveForm
DoCmd.SelectObject acForm, stDocName, True
'change printer to selected
Set Application.Printer = Application.Printers(PS)
MsgBox& Application.Printer.DeviceName
'DoCmd.PrintOut acPrintAll, , , , Me.txtNoOfCopies
DoCmd.SelectObject acForm, MyForm.Name, False
BandL.B_L_Remove
Exit_btnPrintForm_Click:
Exit Sub
Err_btnPrintForm_Click:
MsgBox Err.Description
Resume Exit_btnPrintForm_Click
End Sub