The PDF file is not open at that point of time.
Main Topics
Browse All TopicsHi all
I am getting an access denied error ( error code -2147206458) when i try to use the export option. does anyone has any clue about it? Also on the machine on which i am trying this out, it works with one of the ID's but with id i am trying it fails.
Attached is the code which we are using.
Public Function DO_Crystal(iFileNum As Integer, szRunDate As String, szRunState As String, szRptCode As String, szBrkStr As Integer, szBrkEnd As Integer, szPageCnt As Integer, szReportName As String) As Integer
Dim Report As CRAXDDRT.Report
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim crystal As CRAXDDRT.Application
Dim iRetval As Integer
Dim szsql As String
Dim sPrnName As String
Dim sCmd As String
Dim sPDFPath As String
On Error GoTo Err_handler
CrystalActiveXReportViewer
Set conn = New ADODB.Connection
conn.ConnectionString = "DRIVER={SQL Server};" _
& "SERVER=" + gCtlServer + ";" _
& "DATABASE=" + gCtlAggrDb + ";" _
& "UID=" + GsUserID + ";" _
& "PWD=" + GsPassword + ";"
conn.Open
szsql = "UPDATE Trig_Tbl"
szsql = szsql + " SET run_state = '" + "CRB" + "' "
szsql = szsql + " WHERE run_date = '" + szRunDate + "'"
szsql = szsql + " AND report_code = '" + szRptCode + "'"
conn.Execute szsql
Set rs = New ADODB.Recordset
Select Case szReportName
Case "LB.rpt":
rs.Open "select * from fl_1_bl", conn, adOpenStatic, adLockReadOnly
sPrnName = gszBPrinterName
Case "L31.rpt":
rs.Open "select * from fl_2_bl", conn, adOpenStatic, adLockReadOnly
sPrnName = gszLPrinterName
Case "L60.rpt":
rs.Open "select * from Lp_3_fl", conn, adOpenStatic, adLockReadOnly
sPrnName = gszLPrinterName
Case "IL31.rpt":
rs.Open "select * from lp_4_fl", conn, adOpenStatic, adLockReadOnly
sPrnName = gszLPrinterName
Case "IL60.rpt":
rs.Open "select * from mac_1", conn, adOpenStatic, adLockReadOnly
sPrnName = gszLPrinterName
'Tcs change begins - 07/19/2005
Case "PerInf.rpt"
rs.Open "select * from dbo.PerInftbl", conn, adOpenStatic, adLockReadOnly
sPrnName = gszLPrinterName ' change 1
Case "PerInf_ErrRpt.rpt"
rs.Open "select * from dbo.PerInftbl", conn, adOpenStatic, adLockReadOnly
sPrnName = gszLPrinterName ' change 1
'Tcs change ends - 07/19/2005
End Select
MsgBox "Setting New Crytal Object"
Set crystal = New CRAXDDRT.Application
MsgBox "Setting New Crytal Object - Done"
Set Report = crystal.OpenReport(gszRptF
MsgBox "Opened Report" & gszRptFileLoc & "\" & Trim(szReportName)
Report.DiscardSavedData
Report.Database.SetDataSou
MsgBox "Setting Crystal ReportViewer "
CrystalActiveXReportViewer
MsgBox "Setting Export Options 1"
Report.ExportOptions.Desti
Report.ExportOptions.Forma
Report.DisplayProgressDial
MsgBox "Setting Export Options 1 - Done"
If szReportName = "LB.rpt" Then
gszRptFileLoc = gszRptFileLoc + "\B"
'Tcs change begins - 07/19/2005
ElseIf szReportName = "PerInf.rpt" Then
gszRptFileLoc = gszRptFileLoc + "\Inf"
ElseIf szReportName = "PerInf_ErrRpt.rpt" Then
gszRptFileLoc = gszRptFileLoc + "\Inf"
Else
'Tcs change ends - 07/19/2005
gszRptFileLoc = gszRptFileLoc + "\L"
End If
MsgBox gszRptFileLoc
If Len(Trim(Str$(szBrkStr))) = 1 Then
'Tcs change begins - 07/19/2005
If szReportName = "PerInf.rpt" _
Or szReportName = "PerInf_ErrRpt.rpt" Then
Report.ExportOptions.DiskF
Else
Report.ExportOptions.DiskF
End If
'Tcs change ends - 07/19/2005
Else
'Tcs change begins - 07/19/2005
If szReportName = "PerInf.rpt" _
Or szReportName = "PerInf_ErrRpt.rpt" Then
Report.ExportOptions.DiskF
Else
Report.ExportOptions.DiskF
End If
'Tcs change ends - 07/19/2005
End If
MsgBox "Set Disk File Name"
If szBrkStr = szBrkEnd Then
If szBrkStr = 1 Then
Report.ExportOptions.PDFEx
Else
Report.ExportOptions.PDFEx
Report.ExportOptions.PDFFi
Report.ExportOptions.PDFLa
End If
Else
If szBrkStr = 1 Then
Report.ExportOptions.PDFEx
Report.ExportOptions.PDFFi
Report.ExportOptions.PDFLa
Else
Report.ExportOptions.PDFEx
Report.ExportOptions.PDFFi
Report.ExportOptions.PDFLa
End If
End If
MsgBox "Set report option 2 - Done"
MsgBox "Before Export" ' Fails after this step
Report.Export (False)
MsgBox "After Export"
If Not cSetPrinter.SetPrinterAsDe
If WriteFileRow(iFileNum, "Error Setting up the Milville printer as default") = False Then GoTo Do_CrystalErr
End
End If
MsgBox "Printer Set"
MsgBox "PDF Path to be set"
sPDFPath = Report.ExportOptions.DiskF
MsgBox "PDF path set"
iRetval = PrintPDFs(iFileNum, sPrnName, sPDFPath)
MsgBox "made PDF"
sPrnName = cSetPrinter.m_sPrevPrinter
If Not cSetPrinter.SetPrinterAsDe
If WriteFileRow(iFileNum, "Error reverting the old printer as default") = False Then GoTo Do_CrystalErr
End
End If
rs.Close
conn.Close
DO_Crystal = FnReturnValue.success
Set conn = Nothing
Set crystal = Nothing
Set Report = Nothing
Set rs = Nothing
Exit Function
Do_CrystalErr:
WriteFileRow iFileNum, CStr(Err.Number) + " - " + CStr(Err.Description) + " - Source : DO_Crystal "
Exit Function
Err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
End Function
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Also since it works for one ID, I doubt it is the code but it could be.
The error mentioned only appears in the CR Knowledge Base with reference to CR6.
Since you are trying to export to PDF and it works, I doubt you are using CR6.
THe message refers to using report file names without the .RPT extension.
Another thought if ID refers to a user id, does that user have access to the report files, the database, the directory where the PDF will be written, the TEMP directories?
mlmcc
We are using CR10. By ID I mean a User ID logged on to the Machine ( windows 2003 server).
Let me try these stuff
1. Check for User NTFS permission on the directories having the report, the folder where the report is written to. The C:\Temp folder.
2. Also I created a setup package. I will run this on the server and make sure that all the components are there and registered properly.
Any other guess??
The essential code is
Public Function DO_Crystal(iFileNum As Integer, szRunDate As String, szRunState As String, szRptCode As String, szBrkStr As Integer, szBrkEnd As Integer, szPageCnt As Integer, szReportName As String) As Integer
Dim Report As CRAXDDRT.Report
Dim crystal As CRAXDDRT.Application
CrystalActiveXReportViewer
' Get a SQL connection
' Prepare and execute SQL
Set crystal = New CRAXDDRT.Application
Set Report = crystal.OpenReport(gszRptF
MsgBox "Opened Report" & gszRptFileLoc & "\" & Trim(szReportName)
Report.DiscardSavedData
Report.Database.SetDataSou
CrystalActiveXReportViewer
Report.ExportOptions.Desti
Report.ExportOptions.Forma
Report.DisplayProgressDial
'Set report name
If szBrkStr = szBrkEnd Then
If szBrkStr = 1 Then
Report.ExportOptions.PDFEx
Else
Report.ExportOptions.PDFEx
Report.ExportOptions.PDFFi
Report.ExportOptions.PDFLa
End If
Else
If szBrkStr = 1 Then
Report.ExportOptions.PDFEx
Report.ExportOptions.PDFFi
Report.ExportOptions.PDFLa
Else
Report.ExportOptions.PDFEx
Report.ExportOptions.PDFFi
Report.ExportOptions.PDFLa
End If
End If
MsgBox "Set report option 2 - Done"
MsgBox "Before Export" ' Fails after this step
Report.Export (False)
MsgBox "After Export"
End
End If
Exit Function
Err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
End Function
Ok I checked up the permission and that did not seem to be an issue, so the next step i did was to put in the related dll's in c:\windows\system32. Once i did it and launched the program it gave the following error
The visual basic UFL that implements this function is missing (or u2lcom.dll is missing).
I looked up and the u2lcom.dll was present under c:\windows\system32 an also under c:\program files\common files\...\crystal decisions\2.5\bin.
What could be the missing components?
Business Accounts
Answer for Membership
by: IdoMilletPosted on 2005-10-17 at 14:31:05ID: 15103316
One thing to check is that the pdf file you are exporting to is NOT opened in an acrobat reader...
hth,
- Ido