boblarson
Smeghead
- Local time
- Today, 12:41
- 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:
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?
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?