cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal report date record selection formula gives an error.

0 Kudos
703

I use the following code to feed a record selection formula to a report. I'm using VB.Net and MS SQL Server. "exp_date" is a date type column (Ex: 2021-10-25). getServerDateTime() is my own function to get the server date. "Impersonate" loads the login details to the report. I get the attached error when I'm running this code. What am I doing wrong here?

                Case "Expired Batches"


                    Dim crepExpIt As New crepExpiered
                    Dim curDate As Date = Format(getServerDateTime().Today)  
                    CReportAuthentication.Impersonate(crepExpIt) 
                    crepExpIt.RecordSelectionFormula = "{TB_STOCK.exp_date} <=#" & curdate & "#"
                    CrystalReportViewer1.ReportSource = crepExpIt
                    CrystalReportViewer1.Zoom(85)
                    CrystalReportViewer1.Refresh()
                    CrystalReportViewer1.RefreshReport()

Accepted Solutions (1)

Accepted Solutions (1)

DellSC
Active Contributor

I believe it needs single quotes as if it were a string instead of the #.

-Dell

0 Kudos

Thank you. It worked. But I use # at another formula and its working properly in that. Can u kindly explain why it isn't working here?

DellSC
Active Contributor
0 Kudos

Is the other place where you're using it a date? Or is it another data type?

-Dell

Answers (0)