Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing VB6 form data to Subreports.

Status
Not open for further replies.

nickfatool

IS-IT--Management
Oct 8, 2001
30
AU
CR8.5Dev, VB6, Access97

OK, firstly I've got to apologise for my "Access" mentality and methodologies.

I'm trying to recreate a little native Access functionality using VB and Crystal.
In Access you can have a form with a command button open a report that includes subreports.
The report & subreports can retrieve a value from a textbox on the form that called it and perform calculations.
The report/subreports reference the control on the form via
"Forms![MyForm]![MyTextBox]"

What I'd like to end up with is a form with a single text box and command button, the user will supply a date in the text box and press the command button. The main Crystal report (with 3 subs) opens, the 3 sub reports reference the user's date and return records that match that date.

For now I've written a "UDL" dll that includes a Public variable "GlobalDate" and a function "fDate" and I've referenced "fDate" from within Crystal's record selection formula.

Code:
Option Explicit
Public GlobalDate As Date


Private Sub Class_Initialize()
    GlobalDateFrom = 0
End Sub

Public Function fDate() As Date
Dim sInputDate As String

'Has GlobalDate been initialised?
If GlobalDate = 0 Then
    sInputDate = InputBox("Enter the date to work back from.", "Enter 

Date", Format(Date, "dd/mm/yyyy"))
    GlobalDate = CDate(sInputDate)
Else
    GlobalDate = GlobalDate
End If

fDate = GlobalDate

End Function

This is kind of groovy, as it only asks for the date value once and all subreports can reference it. But I really would like to have users enter the required date on the form they use to open the report.

Any clues would be greatly appreciated.

TIA,

Rob Dexter.
 
Well I got it to work, kind of a scramble of code at the moment, if anyone's interested in it, let me know. It wouldn't be bad to get some help unscambling it anyway..

VB Form passes a value into the shared DLL, Crystal retrieves it from there.

Cheers,

Rob Dexter.
 
It's much easier to use the standard Crystal objects in VB and open up each sub-report and pass the parameter value.

Dim Report As CRAXDRT.Report
Dim SubReport As CRAXDRT.Report
Dim App As CRAXDRT.Application
Dim Sections As CRAXDRT.Sections
Dim Section As CRAXDRT.Section
Dim RepObjs As CRAXDRT.ReportObjects
Dim SubReportObj As CRAXDRT.SubreportObject

Set App = New CRAXDRT.Application
Set Report = App.OpenReport("your.rpt")

Report.Database.Tables(1).SetLogOnInfo ...(login info)

Set Sections = Report.Sections
For n = 1 To Sections.Count
Set Section = Sections.Item(n)
Set RepObjs = Section.ReportObjects
For i = 1 To RepObjs.Count
If RepObjs.Item(i).Kind = crSubreportObject Then
Set SubReportObj = RepObjs.Item(i)
Set SubReport = SubReportObj.OpenSubreport
SubReport.ParameterFields(2).AddCurrentValue "your param value"
End If
Next i
Next n
 
I've been using CPEAUT32.dll, can I get the same object granularity, down to the subreport objects? Or should I change to the DRT before I get in too deep? I would much rather "push" all instructions to Crystal rather than the other way around.
 
I would move to the RDC model and DLLs. That's the stated direction of Crystal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top