angel7170
asked on
Pass Selection Formula to Crystal subreport in VB.NET
Hello Experts,
I have a created a crystal report with a non-linked subreport(different datasource from the main report) in Visual studio 2008. I'm passing a selection formula to the main report and it works fine.
. I have shown the code as below.
The problem is how to pass a selection formula to the subreport?
Also, if the main report is empty it should suppress the main report and display only the subreport.
How to achieve this task? Please advice.
Thank you
Dim StrSelectionUser1 As String
UserNamefromform = Me.Lbl_EmpName1.Text
Datefromform = Now.ToShortDateString
StrSelectionUser1 = "{Telework_Log_Table.USER_ NAME} = '" & UserNamefromform & "' And {Telework_Log_Table.DATEVA LUE} = #" & Datefromform & "#"
'StrSelectionUser2 = "{Other_Equipment.USER_NAM E} = '" & UserNamefromform & "' And {Other_Equipment.DATEVALUE } = #" & Datefromform & "#"
CrystalReportsForm_All.Sho w()
reportdoc1 = "C:\Users\test\Documents\V isual Studio 2008\Projects\RND\RND\Crys talReport_ DirectMS.r pt"
CrystalReportsForm_All.Cry stalReport Viewer1.Re portSource = reportdoc1
CrystalReportsForm_All.Cry stalReport Viewer1.Se lectionFor mula = StrSelectionUser1
I have a created a crystal report with a non-linked subreport(different datasource from the main report) in Visual studio 2008. I'm passing a selection formula to the main report and it works fine.
. I have shown the code as below.
The problem is how to pass a selection formula to the subreport?
Also, if the main report is empty it should suppress the main report and display only the subreport.
How to achieve this task? Please advice.
Thank you
Dim StrSelectionUser1 As String
UserNamefromform = Me.Lbl_EmpName1.Text
Datefromform = Now.ToShortDateString
StrSelectionUser1 = "{Telework_Log_Table.USER_
'StrSelectionUser2 = "{Other_Equipment.USER_NAM
CrystalReportsForm_All.Sho
reportdoc1 = "C:\Users\test\Documents\V
CrystalReportsForm_All.Cry
CrystalReportsForm_All.Cry
ASKER
The subreport is a unlinked subreport and I have not created parameters in the main or the subreport. I'm passing the record selection to the main report through the code written as above. So How to do the same for the unlinked subreport?
I'm new to this programming. please assist. Thank you
I'm new to this programming. please assist. Thank you
reportdoc1.Subreports("nam e").Record SelectionF ormula = "SubReportSelectFormula"
ASKER
Thank you
I used your code as below
CrystalReportsForm_All.Cry stalReport _DirectMS1 .Subreport s("Crystal Report_Sub Report").R ecordSelec tionFormul a = StrSelectionUser2
but it's giving me a error
System.NullReferenceExcept ion - Object reference not set to an instance of an object
Please assist. Thank you
I used your code as below
CrystalReportsForm_All.Cry
but it's giving me a error
System.NullReferenceExcept
Please assist. Thank you
ASKER
I changed my code as shown below. but's still my subreport is not filtered based on the selectionformula.
'StrSelectionUser2 = "{Other_Equipment.USER_NAM E} = '" & UserNamefromform & "' And {Other_Equipment.DATEVALUE } = #" & Datefromform & "#"
If StrSelectionUser2.Length > 0 Then
CrystalReportsForm_All.Cry stalReport _DirectMS1 .Subreport s("Otherre port").Rec ordSelecti onFormula = StrSelectionUser2
End If
'StrSelectionUser2 = "{Other_Equipment.USER_NAM
If StrSelectionUser2.Length > 0 Then
CrystalReportsForm_All.Cry
End If
you have a comment on StrSelectionUser2 try uncommenting the line.
ASKER
Thanks again. I uncommented that line but still its not filtering the report.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Do you need further assistance?
You then specify the selection formula the same way you would for the main, using the same parameters.