g_johnson
asked on
crystal reports XI sp 2 called from VB.Net 2008
In a VB.Net project, the code below comes from my main form. It calls a second form, fCRV which has a single control, a crystal report viewer (crvMain). There are two different reports involved.
I need to modify this code such that I set the log on information for the crystal report (server, database, no integrated security, user id, and password). Both reports use the same connection information.
How is that done in VB.Net (2008)?
Thanks.
I need to modify this code such that I set the log on information for the crystal report (server, database, no integrated security, user id, and password). Both reports use the same connection information.
How is that done in VB.Net (2008)?
Thanks.
Public Shared Sub PrintReport(ByVal f As Form1)
Try
Dim vchrNo As String
'qty mode report is called: ReceiverVariance-CR11.rpt -- change config to QtyModeReport
'voucher mode report is called: APVoucherRecapReport-CR11 -- add to config VoucherModeReport
If Globals.QtyModeIndicator = True Then
fCRV.crvMain.ReportSource = Globals.QtyModeRept
'if clicked, let the report ask for a parameter else pass it a selection formula
If Not Globals.ReportCalledByClick Then
fCRV.crvMain.SelectionFormula = "{ag_ap_match_variance_report.pack_no} = " & Chr(34) & f.billNo.Text & Chr(34)
End If
fCRV.ShowDialog()
Else
fCRV.crvMain.ReportSource = Globals.VoucherModeRept
'if clicked, let the report ask for a parameter else pass it a selection formula
'get voucher number
Dim dr As DataGridViewRow = f.dgvVouchers.SelectedRows(0)
VchrNo = dr.Cells(1).Value.ToString
If Not Globals.ReportCalledByClick Then
fCRV.crvMain.SelectionFormula = "{aptrxfil_sql.vchr_no} = " & Chr(34) & vchrNo & Chr(34)
End If
fCRV.ShowDialog()
End If
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello mimcc.
I can't use a dataset; that part's out of my control. I'm trying to invoke several, pre-written reports. Given my code attached, whereby I set the report viewer source to a certain report, I can't figure out how to reference any of the properties or methods.
For example:
Dim tbCurrent As CrystalDecisions.CrystalRe ports.Engi ne.Table
For Each tbCurrent In fCRV.crvMain.DataBase
is not available to me.
I can't use a dataset; that part's out of my control. I'm trying to invoke several, pre-written reports. Given my code attached, whereby I set the report viewer source to a certain report, I can't figure out how to reference any of the properties or methods.
For example:
Dim tbCurrent As CrystalDecisions.CrystalRe
For Each tbCurrent In fCRV.crvMain.DataBase
is not available to me.
What references have you added to the application for Crystal?
Is this Crystal XI R2?
mlmcc
Is this Crystal XI R2?
mlmcc
ASKER
Ultimately I solved it like this:
Public Shared Sub PrintReport(ByVal f As Form1)
Dim i As Integer
Dim ii As Integer
Dim iii As Integer
Dim vchrNo As String
Dim connInfo As New CrystalDecisions.Shared.Ta bleLogOnIn fo()
Dim objReport As New CrystalDecisions.CrystalRe ports.Engi ne.ReportD ocument
Dim subReportObj As CrystalDecisions.CrystalRe ports.Engi ne.Subrepo rtObject
Dim subReportDoc As New CrystalDecisions.CrystalRe ports.Engi ne.ReportD ocument
Try
If Globals.QtyModeIndicator = True Then
objReport.Load(Globals.Qty ModeRept)
Else
objReport.Load(Globals.Vou cherModeRe pt)
End If
'set connection info
connInfo.ConnectionInfo.Us erID = "sa"
connInfo.ConnectionInfo.Pa ssword = "amergroc2004"
connInfo.ConnectionInfo.Se rverName = Globals.ServerName
connInfo.ConnectionInfo.Da tabaseName = Globals.DatabaseName
For i = 0 To objReport.Database.Tables. Count - 1
objReport.Database.Tables( i).ApplyLo gOnInfo(co nnInfo)
Next
For i = 0 To objReport.ReportDefinition .Sections. Count - 1
For ii = 0 To objReport.ReportDefinition .Sections( i).ReportO bjects.Cou nt - 1
With objReport.ReportDefinition .Sections( i)
If .ReportObjects(ii).Kind = ReportObjectKind.Subreport Object Then
subReportObj = CType(.ReportObjects(ii), CrystalDecisions.CrystalRe ports.Engi ne.Subrepo rtObject)
subReportDoc = subReportObj.OpenSubreport (subReport Obj.Subrep ortName)
For iii = 0 To subReportDoc.Database.Tabl es.Count - 1
subReportDoc.Database.Tabl es(iii).Ap plyLogOnIn fo(connInf o)
Next
End If
End With
Next
Next
'qty mode report is called: ReceiverVariance-CR11.rpt -- change config to QtyModeReport
'voucher mode report is called: APVoucherRecapReport-CR11 -- add to config VoucherModeReport
If Globals.QtyModeIndicator = True Then
' fCRV.crvMain.ReportSource = Globals.QtyModeRept
'if clicked, let the report ask for a parameter else pass it a selection formula
If Not Globals.ReportCalledByClic k Then
objReport.RecordSelectionF ormula = "{ag_ap_match_variance_rep ort.pack_n o} = " & Chr(34) & f.billNo.Text & Chr(34)
'fCRV.crvMain.SelectionFor mula = "{ag_ap_match_variance_rep ort.pack_n o} = " & Chr(34) & f.billNo.Text & Chr(34)
End If
'fCRV.ShowDialog()
Else
' fCRV.crvMain.ReportSource = Globals.VoucherModeRept
'if clicked, let the report ask for a parameter else pass it a selection formula
'get voucher number
Dim dr As DataGridViewRow = f.dgvVouchers.SelectedRows (0)
vchrNo = dr.Cells(1).Value.ToString
If Not Globals.ReportCalledByClic k Then
objReport.RecordSelectionF ormula = "{aptrxfil_sql.vchr_no} = " & Chr(34) & vchrNo & Chr(34)
'fCRV.crvMain.SelectionFor mula = "{aptrxfil_sql.vchr_no} = " & Chr(34) & vchrNo & Chr(34)
End If
'fCRV.ShowDialog()
End If
fCRV.crvMain.ReportSource = Nothing
fCRV.crvMain.ReportSource = objReport
fCRV.ShowDialog()
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
Thanks for pointing me in the right directon.
Public Shared Sub PrintReport(ByVal f As Form1)
Dim i As Integer
Dim ii As Integer
Dim iii As Integer
Dim vchrNo As String
Dim connInfo As New CrystalDecisions.Shared.Ta
Dim objReport As New CrystalDecisions.CrystalRe
Dim subReportObj As CrystalDecisions.CrystalRe
Dim subReportDoc As New CrystalDecisions.CrystalRe
Try
If Globals.QtyModeIndicator = True Then
objReport.Load(Globals.Qty
Else
objReport.Load(Globals.Vou
End If
'set connection info
connInfo.ConnectionInfo.Us
connInfo.ConnectionInfo.Pa
connInfo.ConnectionInfo.Se
connInfo.ConnectionInfo.Da
For i = 0 To objReport.Database.Tables.
objReport.Database.Tables(
Next
For i = 0 To objReport.ReportDefinition
For ii = 0 To objReport.ReportDefinition
With objReport.ReportDefinition
If .ReportObjects(ii).Kind = ReportObjectKind.Subreport
subReportObj = CType(.ReportObjects(ii), CrystalDecisions.CrystalRe
subReportDoc = subReportObj.OpenSubreport
For iii = 0 To subReportDoc.Database.Tabl
subReportDoc.Database.Tabl
Next
End If
End With
Next
Next
'qty mode report is called: ReceiverVariance-CR11.rpt -- change config to QtyModeReport
'voucher mode report is called: APVoucherRecapReport-CR11 -- add to config VoucherModeReport
If Globals.QtyModeIndicator = True Then
' fCRV.crvMain.ReportSource = Globals.QtyModeRept
'if clicked, let the report ask for a parameter else pass it a selection formula
If Not Globals.ReportCalledByClic
objReport.RecordSelectionF
'fCRV.crvMain.SelectionFor
End If
'fCRV.ShowDialog()
Else
' fCRV.crvMain.ReportSource = Globals.VoucherModeRept
'if clicked, let the report ask for a parameter else pass it a selection formula
'get voucher number
Dim dr As DataGridViewRow = f.dgvVouchers.SelectedRows
vchrNo = dr.Cells(1).Value.ToString
If Not Globals.ReportCalledByClic
objReport.RecordSelectionF
'fCRV.crvMain.SelectionFor
End If
'fCRV.ShowDialog()
End If
fCRV.crvMain.ReportSource = Nothing
fCRV.crvMain.ReportSource = objReport
fCRV.ShowDialog()
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
Thanks for pointing me in the right directon.
ASKER
Definitely pointed me in the right direction
One way around this is to pass the report a dataset.
http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx
Does the report run if you provide the connection information when asked?
mlmcc