I have an Access form that has code attached to a button. The code was working perfectly for a long while but yesterday I had to change the name of my printer and now for some reason, instead of exporting to a PDF it comes up with an error about not being
about to find a printer on USB002 and asks if I want to use the default printer. I can get the reports to create by clicking OK but that a huge pain to do when creating 20-30 reports every day.
ERROR MESSAGE
This document was previously formatted for the printer Brother HL-2140 series on USB002, but that printer isn't available. Do you want to use the default printer Xerox?
<OK> <Cancel> <Setup> <Help>
CODE
Private Sub btnPrintReports_Click()
On Error GoTo Err
'-----------------------------------
'Variables
'-----------------------------------
Dim StrSampleID As String
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strQuery As String
Dim strReportName As String
Dim rs As DAO.Recordset 'shortens record set call
Dim strRecordSetSQL As String 'record set string to pass to SQL
Dim strPath As String
Dim strDate As String
strPath = "C:\Users\mineral\Desktop"
Set db = CurrentDb 'sets db[DAO.Dataset] to current data base
strRecordSetSQL = "SELECT Main.CreateReport, Main.Sample_ID, Main.Cusomer_Name, " & _
"Main.Sample_Location, Main.Date_Sampled, Main.[Barge/Train#] " & _
"FROM Main WHERE main.createReport = yes"
Set rs = db.OpenRecordset(strRecordSetSQL) 'Shortens the recordset call
Do While Not rs.EOF 'Do While Records are there
StrSampleID = rs!Sample_ID
'-----------------------------------
'Change Query
'-----------------------------------
'create Qry String
strQuery = "SELECT Main.Sample_ID, Main.Destination," & _
"Main.Moist_AR, Main.Ash_AR, Main.VM_AR, Main.FC_AR, " & _
"Main.Sulf_AR, Main.BTU_AR, Main.Ash_Dry, Main.VM_Dry, " & _
"Main.FC_Dry, Main.Sulf_Dry, Main.BTU_Dry, Main.MAF_BTU, " & _
"Main.FSI_Value, Main.AF_Red_Int, Main.AF_Red_Soft, Main.AF_Red_Hemi, " & _
"Main.AF_Red_Fluid, Main.AF_Ox_Int, Main.AF_Ox_Soft, Main.AF_Ox_Hemi, " & _
"Main.AF_Ox_Fluid, Main.Sample_Wt, Main.Tonnage, Main.Date_Sampled, " & _
"Main.[Barge/Train#], Main.Description, Main.Cusomer_Name, Main.Sample_Location , Main.HGI " & _
"FROM Main WHERE (((Main.Sample_ID)='" & StrSampleID & "'));"
'Write String to Query
CurrentDb.QueryDefs("Qry_Auto_Created_Single_Daily_Sample").SQL = strQuery
'-----------------------------------
'Output Report
'-----------------------------------
strDate = rs!Date_Sampled
strDate = Replace(strDate, "/", "-")
strReportName = strPath & strDate & " " & rs!Cusomer_Name & " at " & rs!Sample_Location & " " & rs![Barge/Train#] & ".pdf"
DoCmd.OutputTo acOutputReport, "Auto_Daily_Sample_ID", acFormatPDF, strReportName, False
rs.MoveNext
Loop
Err:
'MsgBox Error$
Done:
MsgBox ("Reports Created")
End Sub