Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB Databases
| Search | Today's Posts | Mark Forums Read
Pro VB Databases Advanced-level VB coding questions specific to using VB with databases. Beginning-level questions or issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 23rd, 2003, 05:05 PM
Authorized User
 
Join Date: Jul 2003
Location: Montreal, , .
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing a parameter from VB6 to Crystal Report

Hi.
I am passing a parameter from my VB6 code to existing crystal report file. Report is using data from MS SQL database. With out this parameter report is fine. As soon as I pass this parameter, I get an error message: “Logon Failed. Detailes: ADO Error Code: 0x80040e4d. Description: Login failed for user ‘my user name”. SQL State 42000. Native Error 18456
My code is:

Set m_Application = New CRAXDRT.Application
Set m_Report = New CRAXDRT.Report
Set m_Report = m_Application.OpenReport(App.Path & "\ReportName.rpt", 1)
    m_Report.EnableParameterPrompting = False

    Set m_Parameters = m_Report.ParameterFields

    For cnt = 1 To m_Parameters.Count
        Set m_Parameter = m_Parameters.item(cnt)
        If m_Parameter.name = "{?testcode}" Then
           m_Parameter.AddCurrentValue "12345"
        End If
    Next


    frmReportView.CRViewer1.ReportSource = m_Report
    frmReportView.CRViewer1.ViewReport

    frmReportView.Show

Thank you for your help.


  #2 (permalink)  
Old August 10th, 2003, 09:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

You need to 'log on' to each report table before you start manipulating the report. Try something like (assuming SQL Server authentication):
Code:
   For Each crxDataTable In crxReport.Database.Tables
      crxDataTable.SetLogOnInfo sServer, sDatabase, sDBUserName, sDBPassword
      sTblName = crxDataTable.Name
      crxDataTable.Location = sDatabase & ".dbo." & sTblName
      If Not crxDataTable.TestConnectivity Then
         <can't connect error processing>
         Exit Function
      End If
   Next
Note that this must be done for each subreport as well...

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
  #3 (permalink)  
Old February 2nd, 2005, 11:28 PM
Registered User
 
Join Date: Feb 2005
Location: singapore, , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i am using vb6 crystal report 9, i want create a report to view the screen and automaticall export pdf , or excel , i am using the following Code.
    Dim conn As ADODB.Connection
    Dim Rs As ADODB.Recordset
    Dim crystal As CRAXDRT.Application
    Dim report As CRAXDRT.report
    Dim sSQL As String
    Dim CRXDATABASETABLE As CRAXDRT.DatabaseTable

    CRViewer.DisplayBorder = False
    CRViewer.DisplayTabs = False
    CRViewer.EnableDrillDown = False
    CRViewer.EnableRefreshButton = False

    Set conn = New ADODB.Connection
    conn.CursorLocation = adUseClient
    conn.ConnectionString = "Provider=SQLOLEDB;DATA SOURCE=dbserver;DATABASE=supply;USER ID=sa;PASSWORD=sa"
    conn.Open


    Set Rs = New ADODB.Recordset

        sSQL = ""
        sSQL = "Select * From TblSup_EnquiryH, TblJobSheet, TblSup_EnquiryD, TblSup_EnquiryE "
        sSQL = sSQL & " Where TblJobSheet.JobNumber = TblSup_EnquiryH.JobNumber "
        sSQL = sSQL & " and TblSup_EnquiryD.JobNumber = TblSup_EnquiryH.JobNumber "
        sSQL = sSQL & " and TblSup_EnquiryE.JobNumber = TblSup_EnquiryH.JobNumber "
        sSQL = sSQL & " and TblSup_EnquiryH.JobNumber = " & 12013
        sSQL = sSQL & " and TblSup_EnquiryE.PatchNo = " & "'" & "SE1" & "'"



    Rs.Open sSQL, conn, adOpenStatic, adLockReadOnly
    Set crystal = New CRAXDRT.Application 'MANAGES REPORTS
    Set report = crystal.OpenReport("C:\pALCOLATEST\PALCO\REPORT\RP TSUPPLIERENQUIRY5.RPT")
    For Each CRXDATABASETABLE In report.Database.Tables
        CRXDATABASETABLE.ConnectionProperties("USER ID") = "sa"
        CRXDATABASETABLE.ConnectionProperties("password") = "sa"
    Next CRXDATABASETABLE


    report.DiscardSavedData
    report.Database.SetDataSource Rs
    CRViewer.ReportSource = report
    CRViewer.ViewReport
    Do While CRViewer.IsBusy
        DoEvents
    Loop
    report.ExportOptions.DiskFileName = "c:\PalcoLatest\Palco\Report\supEnquiry.XLS"
    report.ExportOptions.DestinationType = crEDTDiskFile
    report.ExportOptions.FormatType = crEFTExcel50
    report.Export False
    CRViewer.Zoom 94
    Rs.Close
    Set Rs = Nothing
    conn.Close
    Set conn = Nothing
    Set crystal = Nothing
    Set report = Nothing
--- end

Note : i have created report earlier using ODBC , tHIS CODE USING OLEDB CONNECTION. SOME TIME THIS CODE GIVEN SOME NETWORK ERROR IT AFFECTED OTHER NETWORK ALSO. I NEED TO VIEW THE REPORT AND EXPORT EXCEL OR PDF USING SQLQUERY.
PLS HELP ME MY PROBLEM.
BY
CHANDRA.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Parameter in Crystal report 10 aarunlal ASP.NET 2.0 Professional 2 April 25th, 2007 05:57 AM
crystal report passing multiple parameter noppanit C# 0 March 20th, 2007 12:32 PM
Crystal report, passing parameter suni_kutty Crystal Reports 2 October 7th, 2004 03:13 AM
passing parameter to crystal report.net shamala Crystal Reports 2 August 19th, 2004 02:04 AM
Passing a parameter from VB6 code to Crystal Repor pavel VB How-To 0 July 17th, 2003 09:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.