Question

Access denied Error when Doing an Export to PDF.

Asked by: pra_kumar03

Hi 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
    CrystalActiveXReportViewer1.EnableRefreshButton = False
   
   
    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(gszRptFileLoc + "\" + Trim(szReportName), 0)
    MsgBox "Opened Report" & gszRptFileLoc & "\" & Trim(szReportName)
    Report.DiscardSavedData
    Report.Database.SetDataSource rs
   
    MsgBox "Setting Crystal ReportViewer "
    CrystalActiveXReportViewer1.ReportSource = Report
    MsgBox "Setting Export Options 1"
    Report.ExportOptions.DestinationType = crEDTDiskFile
    Report.ExportOptions.FormatType = crEFTPortableDocFormat
    Report.DisplayProgressDialog = False
    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.DiskFileName = gszRptFileLoc + "\PERIINFL" + szRptCode + "_" + Mid(szRunDate, 1, 2) + Mid(szRunDate, 4, 2) + Mid(szRunDate, 7, 4) + "_0" + Trim(Str$(szBrkStr)) + ".PDF"
        Else
            Report.ExportOptions.DiskFileName = gszRptFileLoc + "\" + szRptCode + "_" + Mid(szRunDate, 1, 2) + Mid(szRunDate, 4, 2) + Mid(szRunDate, 7, 4) + "_0" + Trim(Str$(szBrkStr)) + ".PDF"
        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.DiskFileName = gszRptFileLoc + "\PERIINFL" + szRptCode + "_" + Mid(szRunDate, 1, 2) + Mid(szRunDate, 4, 2) + Mid(szRunDate, 7, 4) + "_" + Trim(Str$(szBrkStr)) + ".PDF"
        Else
            Report.ExportOptions.DiskFileName = gszRptFileLoc + "\" + szRptCode + "_" + Mid(szRunDate, 1, 2) + Mid(szRunDate, 4, 2) + Mid(szRunDate, 7, 4) + "_" + Trim(Str$(szBrkStr)) + ".PDF"
        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.PDFExportAllPages = True
        Else
            Report.ExportOptions.PDFExportAllPages = False
            Report.ExportOptions.PDFFirstPageNumber = ((szBrkStr - 1) * 4000) + 1
            Report.ExportOptions.PDFLastPageNumber = szPageCnt * 2 + 2
        End If
           
    Else
        If szBrkStr = 1 Then
            Report.ExportOptions.PDFExportAllPages = False
            Report.ExportOptions.PDFFirstPageNumber = ((szBrkStr - 1) * 4000) + 1
            Report.ExportOptions.PDFLastPageNumber = ((szBrkStr - 1) * 4000) + 4000
        Else
            Report.ExportOptions.PDFExportAllPages = False
            Report.ExportOptions.PDFFirstPageNumber = ((szBrkStr - 1) * 4000) + 1
            Report.ExportOptions.PDFLastPageNumber = ((szBrkStr - 1) * 4000) + 4000
        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.SetPrinterAsDefault(sPrnName) Then
        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.DiskFileName
    MsgBox "PDF path set"
    iRetval = PrintPDFs(iFileNum, sPrnName, sPDFPath)
    MsgBox "made PDF"

    sPrnName = cSetPrinter.m_sPrevPrinterDevName
    If Not cSetPrinter.SetPrinterAsDefault(sPrnName) Then
       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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-10-17 at 12:46:18ID21597977
Tags

function

,

access

Topic

Crystal Reports Software

Participating Experts
2
Points
250
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. An exception occurred: 'RS.open'
    sometimes, this error will occurred on and off. but, sometimes it is working perfectly, no error! does anyone know y is it so? Error Type: Microsoft VBScript runtime (0x800A01FB) An exception occurred: 'RS.open' /alai/backoffice/product/product.asp, line 119 thanks
  2. rs.open syntax
    What is the syntax for the following command rs.open I have tried rs.open "SELECT * FROM jobs" but is still says it is incorect! Any help would be appreciated!
  3. rs.open gives "object required" error
    I am revising a piece of code I use in another site. For some reason, I keep getting an "Object required" at the rs.open statement. The same statement works in other parts of this page. I've included the piece of code causing the problem. All else works if I rem...
  4. Crystal Reports 8.5 & Creating a PDF
    I have a crystal report created. I am using version 8.5. What I am trying to do is through VB is click a button in VB.... Based on a select query go into a table pick up the account ID , based on that accountID have that crystal report be generated with that ID's related i...
  5. VBScript: ADODB: What is the difference between Conn…
    I see a few different codes: Set Conn = CreateObject("ADODB.Connection") Set RS = CreateObject("ADODB.Recordset") Conn.Provider = "ADSDSOObject" Conn.Open "ADs Provider" ConnStr = "mystringhere" Set RS = Conn.Execute(Conn...
  6. Crystal Reports Export to PDF not working
    I have a question concerning crystal reports from within Vsual Studio. I have a report that is created that will be about 30 pages, works fine, but using the crystal reports viewer, it doesn't provide me a good mechanism for printing the report. I thought that if I converted...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

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

 

by: pra_kumar03Posted on 2005-10-17 at 14:33:03ID: 15103328

The PDF file is not open at that point of time.

 

by: IdoMilletPosted on 2005-10-17 at 14:43:47ID: 15103390

Clearly, most of the code above has nothing to do with the error.  Can you reduce it to the essential portion that causes the error?

Also, explain what you mean by ID.  A parameter value?  A user ID logged in?

Cheers,
- Ido

 

by: mlmccPosted on 2005-10-17 at 16:22:05ID: 15103837

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

 

by: pra_kumar03Posted on 2005-10-18 at 06:42:16ID: 15107285

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
      CrystalActiveXReportViewer1.EnableRefreshButton = False
   
    ' Get a SQL connection
    ' Prepare and execute SQL

        Set crystal = New CRAXDDRT.Application

    Set Report = crystal.OpenReport(gszRptFileLoc + "\" + Trim(szReportName), 0)
    MsgBox "Opened Report" & gszRptFileLoc & "\" & Trim(szReportName)
    Report.DiscardSavedData
    Report.Database.SetDataSource rs
   

    CrystalActiveXReportViewer1.ReportSource = Report

    Report.ExportOptions.DestinationType = crEDTDiskFile
    Report.ExportOptions.FormatType = crEFTPortableDocFormat
    Report.DisplayProgressDialog = False

    'Set report name

       
   
    If szBrkStr = szBrkEnd Then
        If szBrkStr = 1 Then
            Report.ExportOptions.PDFExportAllPages = True
        Else
            Report.ExportOptions.PDFExportAllPages = False
            Report.ExportOptions.PDFFirstPageNumber = ((szBrkStr - 1) * 4000) + 1
            Report.ExportOptions.PDFLastPageNumber = szPageCnt * 2 + 2
        End If
           
    Else
        If szBrkStr = 1 Then
            Report.ExportOptions.PDFExportAllPages = False
            Report.ExportOptions.PDFFirstPageNumber = ((szBrkStr - 1) * 4000) + 1
            Report.ExportOptions.PDFLastPageNumber = ((szBrkStr - 1) * 4000) + 4000
        Else
            Report.ExportOptions.PDFExportAllPages = False
            Report.ExportOptions.PDFFirstPageNumber = ((szBrkStr - 1) * 4000) + 1
            Report.ExportOptions.PDFLastPageNumber = ((szBrkStr - 1) * 4000) + 4000
        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

 

by: mlmccPosted on 2005-10-18 at 20:01:00ID: 15113187

Does the user in question have appropriate permissions in the database?

mlmcc

 

by: pra_kumar03Posted on 2005-10-19 at 06:01:46ID: 15115397

The user in question has database permission....
Any guess on the access required to use the export function of  CRAXDDRT.Report ? This will help us verify if the user has the right NTFS permissions on all the required folder? For example Temp folder , and ???

 

by: IdoMilletPosted on 2005-10-19 at 06:30:36ID: 15115617

Why are you using Carxddrt.dll and not craxdrt.dll?

Craxddrt.dll requires report creation api license...

 

by: mlmccPosted on 2005-10-19 at 20:32:07ID: 15121556

SInce I haven't used the CRAXDDRT library, is the license required to use it or only if you use one of the royalty functions?

I agree, unless you need CRAXDDRT, use CRAXDRT.

mlmcc

 

by: pra_kumar03Posted on 2005-10-20 at 05:53:54ID: 15123784

I am myself not sure why CRAXDDRT was used. I am trying to help some one figure out the issue. Let me try asking them about it.

 

by: pra_kumar03Posted on 2005-10-20 at 14:26:03ID: 15128750

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?

 

by: mlmccPosted on 2005-10-20 at 20:59:48ID: 15130383

Does the report use functions from a User Function Library (UFL)?  Check the formulas.

mlmcc

 

by: pra_kumar03Posted on 2005-12-29 at 09:50:24ID: 15572041

The issue with that whole thing was that the reports file were being accessed thru a share name rather than the direct folder structure. And as this users did not have the share level permission (though having NTFS permission to the folder) it was giving the problem

 

by: mlmccPosted on 2005-12-29 at 19:07:31ID: 15575497

Glad i could help

mlmcc

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...