Share via

export to PDF causing printer error after printer name change

Anonymous
2011-12-16T14:14:46+00:00

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

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2011-12-16T15:49:50+00:00

Do your reports have specified printers in their setup or do they all use the default printer? If the former, you will have to change them to a printer you have installed. If the latter, you probably only have to go into your printers list and select a default printer.

The reason is that when Access opens a report it ties it to the default printer or th especified printer automatically even if you don't physically print it.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2011-12-16T16:13:32+00:00

    I had changed the name of the printer back to what it originally was so I, opened the report in design view, then changed the name of the printer and it popped up with the dialog boxes mentioned above.  This time when I hit ok it seemed to fix it permanently.

    Was this answer helpful?

    0 comments No comments