-
How do I construct a SelectionFormula that uses a date in VB? I am using SQL Server 6.5.
My VB6 code looks like this:
Private Sub cmdPrint_Click()
Dim rptSql As String
Dim rptDate As Date
rptSql = "SELECT * FROM CheckRegister WHERE {CheckRegister.bank_statement_date}=Date('"
rptSql = rptSql & cboStatementDate.Text + "')"
CrystalReport1.SelectionFormula = rptSql
CrystalReport1.Action = 1
End Sub
I have tried many variations on this formula, such as using the string variable alone, in quotes, and using a date variable instead of a string variable, but nothing seems to work. I keep getting the error message "The remaining text does not appear to be part of the formula".
Does the date have to converted to a different format?
If any one has a solution, I would greatly appreciate it.
-
Excuse me if I am wrong, but doesn't you have to put the string in the -->CrystalReport.SqlQuery<---
or something like that.
This if You are using Crystalreports that came with VS.
-
Parameters for function Date() in Crystal Reports are 3: year, month and day. You can use:
Code:
rptSql = "{CheckRegister.bank_statement_date}="
rptSql = rptSql & "Date(" & Year(cboStatementDate.Text) & ", " & Month(cboStatementDate.Text) & ", " & Day(cboStatementDate.Text) & ")"
Hope it works!
[Edited by JMuller on 09-15-2000 at 04:22 PM]