Results 1 to 3 of 3

Thread: Crystal Reports Selection Formula, SQL

  1. #1
    Guest
    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.


  2. #2
    Guest

    Wink

    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.

  3. #3
    Lively Member
    Join Date
    Apr 2000
    Location
    Rafaela (Argentine)
    Posts
    107
    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]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width