Error 2212 - Can't Print This Object (1 Viewer)

boblarson

Smeghead
Local time
Today, 05:09
Joined
Jan 12, 2001
Messages
32,059
I am having an issue on Citrix. We have code which I have posted in the forum which prints to PDF. But the interesting thing is that when run for the very first time from someone with a new profile, it shows up with this error. So, the person can just click OK and then go click the button to send to the PDF file again and then it works fine for as long as they have that profile. Unfortunately our Citrix folks have things set so that you get a new profile every time you log in. So, if I log in originally my profile would be ss23904 and then the next time ss23904.1 the next time ss23904.2 etc.

I think it has to so with the default printer but can't figure out why. Our code changes the default printer just before printing but it doesn't seem to recognize it on the first time through. The code is:

Code:
Public Function RunReportAsPDF(prmRptName As String, _
                               prmPdfName As String) As Long
' Returns TRUE if a PDF file has been created
Dim AdobeDevice As String
Dim strDefaultPrinter As String
'Find the Acrobat PDF device
AdobeDevice = GetRegistryValue(HKEY_CURRENT_USER, _
                               "Software\Microsoft\WIndows NT\CurrentVersion\Devices", _
                               "Adobe PDF")
If AdobeDevice = "" Then    ' The device was not found
    MsgBox "You must install Acrobat Writer before using this feature"
    RunReportAsPDF = False
    Exit Function
End If
' get current default printer.
[COLOR=red][B]strDefaultPrinter = Application.Printer.DeviceName[/B][/COLOR]
[COLOR=red][B]Set Application.Printer = Application.Printers("Adobe PDF")[/B][/COLOR]
'Create the Registry Key where Acrobat looks for a file name
CreateNewRegistryKey HKEY_CURRENT_USER, _
                     "Software\Adobe\Acrobat Distiller\PrinterJobControl"
'Put the output filename where Acrobat could find it
[COLOR=black]SetRegistryValue HKEY_CURRENT_USER, _[/COLOR]
[COLOR=black]                "Software\Adobe\Acrobat Distiller\PrinterJobControl", _[/COLOR]
[COLOR=black]                Find_Exe_Name(CurrentDb.Name, CurrentDb.Name), _[/COLOR]
[COLOR=black]                prmPdfName[/COLOR]
 
On Error GoTo Err_handler
[B][COLOR=red]DoCmd.OpenReport prmRptName, acViewNormal   'Run the report[/COLOR][/B]
While Len(Dir(prmPdfName)) = 0              ' Wait for the PDF to actually exist
    DoEvents
Wend
RunReportAsPDF = -1       ' Mission accomplished!
Normal_Exit:
Set Application.Printer = Application.Printers(strDefaultPrinter)   ' Restore default printer
On Error GoTo 0
Exit Function
Err_handler:
If Err.Number = 2501 Then       ' The report did not run properly (ex NO DATA)
    RunReportAsPDF = 2
    Resume Normal_Exit
Else
    RunReportAsPDF = 0      ' The report did not run properly (anything else!)
    MsgBox "Unexpected error #" & Err.Number & " - " & Err.Description
    Resume Normal_Exit
End If
End Function

I wonder if the timing is such that it just takes longer to do than for it to get to run the report. Perhaps a bit of code to slow it down a bit might help. What do you think?
 

boblarson

Smeghead
Local time
Today, 05:09
Joined
Jan 12, 2001
Messages
32,059
Strange thing again with this. The Citrix admin cleared all of the profiles and now it doesn't throw that 2212 error on our Test server or our QA server, but even though we have specified the location and the printer it pops up with a save dialog the very first time someone tries to print to PDF from their Citrix Profile. After hitting cancel, everything works as intended from that point on out until they log out and log back into their Citrix account.

This is very annoying.
 

Kryst51

Singin' in the Hou. Rain
Local time
Today, 07:09
Joined
Jun 29, 2009
Messages
1,898
Did you get this figured out?
 

Users who are viewing this thread

Top Bottom