Share via

Variable not defined on OutputTo acFormatPDF

Anonymous
2012-04-10T21:07:33+00:00

I have several reports that I output to PDF.  Just these past couple of weeks, I have one PC that can no longer run any code that outputs to a PDF.  Below is an example line of code but he gets this on other reports.

DoCmd.OutputTo acOutputReport, "rptMonthEndComputerCounts", acFormatPDF, "C:\Temp\ComputerCounts.pdf"

I get "Variable not defined" and the debugger highlights acFormatPDF.  Debug-Compile does not produce any errors on my PC.  We are both running Access 2010.  References listed are the same and none are "Missing".

Ideas?

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

6 answers

Sort by: Most helpful
  1. Anonymous
    2012-04-13T02:58:17+00:00

    Hi,

    It loaded Access 2003 is because that Access 2003 installed after Access 2010.

    You can press Win+R and type "Regedit" in the Run dialog box, and then navigate to:

    HKEY_CLASSES_ROOT\Access.MDBFile\shell\Open\command

    See the Default value in the right window.

    If Access 2010:

    "D:\Microsoft Office\Office14\MSACCESS.EXE" /NOSTARTUP "%1" %2 %3 %4 %5 %6 %7 %8 %9

    Why acFormatPDF doesn't work in Access 2003?

    These are Access 2003 file formats:

    Const acFormatASP = "Microsoft Active Server Pages (*.asp)"

    Const acFormatDAP = "Microsoft Access Data Access Page (*.htm; *.html)"

    Const acFormatHTML = "HTML (*.html)"

    Const acFormatIIS = "Microsoft IIS (*.htx; *.idc)"

    Const acFormatRTF = "Rich Text Format (*.rtf)"

    Const acFormatSNP = "Snapshot Format (*.snp)"

    Const acFormatTXT = "MS-DOS Text (*.txt)"

    Const acFormatXLS = "Microsoft Excel (*.xls)"

    These are Access 2010 file formats:

    Const acFormatHTML = "HTML (*.html)"

    Const acFormatPDF = "PDF Format (*.pdf)"

    Const acFormatRTF = "Rich Text Format (*.rtf)"

    Const acFormatSNP = "Snapshot Format (*.snp)"

    Const acFormatTXT = "MS-DOS Text (*.txt)"

    Const acFormatXLS = "Microsoft Excel (*.xls)"

    Const acFormatXLSB = "Microsoft Excel Binary Workbook (*.xlsb)"

    Const acFormatXLSX = "Microsoft Excel Workbook (*.xlsx)"

    Const acFormatXPS = "XPS Format (*.xps)"

    Cheers,

    Cristin

    Was this answer helpful?

    3 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2012-04-13T13:29:39+00:00

    I just went into File Types and changed which Access version loaded when an MDB was clicked.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2012-04-12T19:45:10+00:00

    Thanks.  I did a repair on his machine then tried running the program (under my login id) and it worked fine - but when he logged in, it failed.

    I did some more digging and found that even though he had Access 2010 installed on his PC, He also had Access 2003 installed and when he double clicked on the MDB it loaded Access 2003.  Changing which Access version loaded when clicking the MDB type fixed the issue. 

    Not sure why that option didn't work in 2003 - but none of my users should still be using that version of Access anymore.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2012-04-11T08:15:17+00:00

    Hi,

    The acFormatPDF is a  predefined constant member of Access Constants Enumeration. It is defined as below:

        Const acFormatPDF = "PDF Format (*.pdf)"

    Please type the following code (do not copy and paste) in the VBE environment to see if there is an auto-complete list after typing the dot:

        Debug.Print Access.Constants.acFormatPDF

    If you cannot see the auto-complete list, please check Options >> Editor >> Auto List Members.

    Then add the acFormatPDF declaration before DoCmd...

         ' Force to declare a constant.

         Const acFormatPDF = "PDF Format (*.pdf)"

         DoCmd.OutputTo acOutputReport, "rptMonthEndComputerCounts", acFormatPDF, "C:\Temp\ComputerCounts.pdf"

    OR directly use the constant value

         DoCmd.OutputTo acOutputReport, "rptMonthEndComputerCounts", "PDF Format (*.pdf)", "C:\Temp\ComputerCounts.pdf"

    If no avail, you might try to repair your Office via Control Panel >> Uninstall a program >> Right-click the Office program >> Change >> Repair

    Best Regards (=^ω^=),

    Cristin

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2012-04-10T21:33:28+00:00

    Hi,

    I know very little about Access but if this was Excel I would expect the problem to be un-dimmed variable and that your colleagues application is set to require variable declaration so you have choices.

    Dim acFormatPDF

    at the top of the code

    or on your colloegues machine in VB editor Tools|Options|Editor tab and un-check 'Require variable declaration'

    Was this answer helpful?

    0 comments No comments