We help IT Professionals succeed at work.
Get Started

Pass Selection Formula to Crystal subreport in VB.NET

angel7170 asked
Last Modified: 2013-11-26
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.DATEVALUE} = #" & Datefromform & "#"
        'StrSelectionUser2 = "{Other_Equipment.USER_NAME} = '" & UserNamefromform & "' And {Other_Equipment.DATEVALUE} = #" & Datefromform & "#"

        reportdoc1 = "C:\Users\test\Documents\Visual Studio 2008\Projects\RND\RND\CrystalReport_DirectMS.rpt"
        CrystalReportsForm_All.CrystalReportViewer1.ReportSource = reportdoc1
        CrystalReportsForm_All.CrystalReportViewer1.SelectionFormula = StrSelectionUser1
Watch Question
Director of Information Technology
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE