
Parsing parameter from VB 6.0 to Crystal Report 7.0
Hi Tammy,
I use the ActiveX control and my code looks like this:
'Users choose from several reports listed in a menu option
Public Sub ViewReports(IndexNumber)
Dim strReportName As String
Dim strParameter As String
Dim strQuery As String
strParameter = "Summary"
'I use the same report to offer either a summary view or a detailed view of
the data and the user chooses
'items from a drop-down list to restrict the data. Based on which report
the user has chosen, a routine is called to
'determine which items from the drop-down the user chose.
'Determine which contact(s) or section(s) the user has chosen from the
drop-down
Select Case IndexNumber
Case 0, 1, 2
If boolAllSelected = False Then frmOutput.CollectSections
If boolNoSelection = True Then Exit Sub
strReportName = IIf(intIndex = 2,
"ContactsBelongingToSectionByCompany.rpt", "ContactsBelongingToSection.rpt")
If intIndex = 0 Or intIndex = 2 Then strParameter = "Detail"
Case 3
strReportName = "ContactsByCompany.rpt"
Case 4
If boolAllSelected = False Then frmOutput.CollectAddresses
If boolNoSelection = True Then Exit Sub
strReportName = "SectionsForContact.rpt"
Case 6
strReportName = "Residency Report.rpt"
Case 7
strReportName = "Sections.rpt"
End Select
'Pass the appropriate report file name to the Crystal Report object
frmOutput.CR.ReportFileName = strReportPath & strReportName
'Create the required query to send to the report object so that it will
display the desired data
With frmOutput.CR
Select Case intIndex
Case 0, 1, 2
'Passing a parameter requires three pieces of information:
Name of parameter, the parameter value
'and "True" to prevent the user from being prompted
.ParameterFields(0) = "Report_Type;" & strParameter &
";True"
If boolAllSelected = True Then
.SQLQuery = "Select * From Addresses RIGHT JOIN
Section_Members ON " & _
"addresses.address_id =
section_members.address_id RIGHT JOIN Sections ON " & _
"section_members.section_code =
sections.section_code " & _
"Where sections.section_code <> " &
SQLQuote("ZZ")
Else
.SQLQuery = "Select * From Addresses RIGHT JOIN
Section_Members ON " & _
"addresses.address_id = section_members.address_id
RIGHT JOIN Sections ON " & _
"section_members.section_code =
sections.section_code " & _
"Where sections.section_desc in " & strSelection
End If
Case 4
.ParameterFields(0) = ""
If boolAllSelected = True Then
.SQLQuery = "Select * From Addresses LEFT JOIN
Section_Members ON " & _
"addresses.address_id =
section_members.address_id LEFT JOIN Sections ON " & _
"section_members.section_code =
sections.section_code"
Else
.SQLQuery = "Select * From Addresses LEFT JOIN
Section_Members ON " & _
"addresses.address_id = section_members.address_id
LEFT JOIN Sections ON " & _
"section_members.section_code =
sections.section_code " & _
"Where addresses.address_id in " & strSelection
End If
Case 7
.ParameterFields(0) = ""
.SQLQuery = "SELECT Sections.section_code,
Sections.section_desc, " & _
"Section_Members.section_code From " & _
"Sections LEFT JOIN Section_Members ON " & _
"Sections.section_code =
Section_Members.section_code "
'Set the specified subreport as the target of property changes
.SubreportToChange = "sections_subreport"
.SQLQuery = "SELECT Sections.section_code,
Sections.section_desc, " & _
"Section_Members.address_id From " & _
"Sections LEFT JOIN Section_Members ON " & _
"Sections.section_code =
Section_Members.section_code "
Case Else
.SQLQuery = ""
.ParameterFields(0) = ""
End Select
.WindowAllowDrillDown = False
'Connect to the database through an ODBC connection via a system DSN.
Send the report to the
'user's screen and maximize the window
.Connect = "DSN=" & strServer & ";UID=;PWD=;DSQ=" & strDatabase
.Destination = crptToWindow
.WindowShowGroupTree = True
.WindowShowSearchBtn = True
.WindowShowPrintSetupBtn = True
.WindowState = crptMaximized
.PageFirst
.Action = True
End With
'Set the main report as the target of property changes
frmOutput.CR.SubreportToChange = ""
frmOutput.CR.Reset
End Sub
I hope this helps
Bob Holmes
Quote:
> Hi Bob,
> Thank's for your answer.
> Can you help me, how to make a new query in CR 7.0, so I can call the
> property sqlquery from my vb application ?
> Thanks.