Hey all,
I am trying to try get a crytal report running properly. A "Hello World"
report that does not add criteria to the record selection formula of the
report (either in the development tool, or in the code) works fine.
However, when I try to add any parameter through the record selection
formula and/or the report parameters method, the report crashes.
I have tried each of the methods:
1. Use the Record Selection Formula property:
crReportDocumen t.DataDefinitio n.RecordSelecti onFormula = "{qryTest.I D} =
54"
2. Use the Crystal Parameters collection(s)
crParameterFiel dDefinitions =
crReportDocumen t.DataDefinitio n.ParameterFiel ds
crParameterFiel dDefinition = crParameterFiel dDefinitions.It em("[@TestID]")
crParameterValu es = crParameterFiel dDefinition.Cur rentValues
crParameterDisc reteValue = New
CrystalDecision s.Shared.Parame terDiscreteValu e()
crParameterDisc reteValue.Value = 54
crParameterValu es.Add(crParame terDiscreteValu e)
crParameterFiel dDefinition.App lyCurrentValues (crParameterVal ues)
Both of the methods above work fine on my development machine but the
testing server gives these errors.
I also set the record selection formula in the report to automatically set
the TestID parameter = 54 and then tested that report on the testing server
and everything worked.
So the issue seems to be with populating the crystal report's parameters at
runtime. The error that comes back with a logon failure at the .Export
line.
I have tried two methods to logon to the reports:
############### #####
Basic:
With tliTableLogonIn fo.ConnectionIn fo
.ServerName = m_strDSNName
.DatabaseName = m_strDatabase
.UserID = m_strUserId
.Password = m_strPassword
End With
'setup each connection in the report
For Each tTable In crReportDocumen t.Database.Tabl es
tTable.ApplyLog OnInfo(tliTable LogonInfo)
Next tTable
############### #####
and Complex (loops through sub-reports):
Dim mySection As Section
Dim mySections As Sections
Dim myReportObject As ReportObject
Dim myReportObjects As ReportObjects
Dim mySubReportObje ct As SubreportObject
Dim mySubRepDoc As New ReportDocument( )
'Declare all of the sections of the main report
mySections = crReportDocumen t.ReportDefinit ion.Sections
'Loop through the sections in the main report to find the subreport objects
'then set the logon information to the subreport
Dim myLogin As CrystalDecision s.Shared.TableL ogOnInfo
For Each mySection In mySections
myReportObjects = mySection.Repor tObjects
For Each myReportObject In myReportObjects
If myReportObject. Kind = ReportObjectKin d.SubreportObje ct Then
'Subreport Found - convert the report object to a sub report type
mySubReportObje ct = CType(myReportO bject, SubreportObject )
'Set the specific instance of this subreport
mySubRepDoc = mySubReportObje ct.OpenSubrepor t
(mySubReportObj ect.SubreportNa me)
'Set the login information for the current subreport(found )
For Each crTable In mySubRepDoc.Dat abase.Tables
myLogin = crTable.LogOnIn fo
myLogin.Connect ionInfo.ServerN ame = m_strDSNName
myLogin.Connect ionInfo.Databas eName = m_strDatabase
myLogin.Connect ionInfo.UserID = m_strUserId
myLogin.Connect ionInfo.Passwor d = m_strPassword
crTable.ApplyLo gOnInfo(myLogin )
Next
End If
Next
Next
############### #####
Does anyone know of other methods to filter a report at runtime? Or is
there a Crystal DLL that I need to move from my dev machine to the server
to allow for the record selection properties to be set at runtime?
OR ANY OTHER INFO WOULD BE GREAT!!!
Thanks,
TJ