Search code examples
vb.netcrystal-reports

How to remove recordselectionformula in crystal reports using vb.net


In my application, user selects a customer from a list. I then use this selected customer (CustID is id of selected customer) to filter records in crystal report using recordselectionformula. However the user is allowed to view report without selecting a customer. In this case CustID is zero and there should be no recordselectionformula. My code is given below.

if CustID>0 then 'this part is working fine
    crystalreport.recordselectionformula="{vSaleReport;1.CustomerID}=" & CustID
else
    crystalreport.recordselectionformula=""  'this line is not working
endif

When user selects a customer (CustID>0), recordselectionformula is set and crystal report filters the records as expected. However when user does not select a customer (CustID=0), previously set recordselectionformula is not removed and report is not displayed for all customers. It still shows filtered data according to previously selected customer.

Can anyone guide me how to remove previously set recordselectionformula.

Thanks


Solution

  • When you are supplying the null it won't return any results instead pass the database field which will retrive all results

    Here is the trick... try this:

    if CustID>0 then 'this part is working fine
        crystalreport.recordselectionformula="{vSaleReport;1.CustomerID}=" & CustID
    else
        crystalreport.recordselectionformula="{vSaleReport;1.CustomerID}=" & {vSaleReport;1.CustomerID}
    endif
    

    I am not sure about VB code check syntax once