Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Date variable in SQL (2002)

    SQLSessionDate = "SELECT tblSession.* FROM tblSession " & _
    "WHERE Session_Date = " & dteSessionDate & ";"
    returns a Type Mismatch error - can anyone tell me what's wrong with my syntax, the field Session_Date is a date field and the variable dteSessionDate is declared as date.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Date variable in SQL (2002)

    Is this running against Access or SQL Server? In either case, you need to delimit the date in the SQL string, but the delimiters are different in Access {#}and in SQL ('), plus if the back end is SQL Server, you have to watch out for smalldatetime fields as opposed to datetime fields. Can you add some detail on the problem?
    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Date variable in SQL (2002)

    I have tried surrounding the variable in # eg -
    SQLSessionDate = "SELECT tblSession.* FROM tblSession " & _
    "WHERE Session_Date = #" & dteSessionDate & "#;"
    with the same result. Running a jet backend but may need to upsize in the future.

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Date variable in SQL (2002)

    You can try :
    SQLSessionDate = "SELECT tblSession.* FROM tblSession " & _
    "WHERE Session_Date = #" & Format(dteSessionDate,"mm/dd/yyyy") & "#;"

    If you still get an error put a msgbox after you statement :
    SQLSessionDate = "SELECT tblSession.* FROM tblSession " & _
    "WHERE Session_Date = #" & dteSessionDate & "#;"
    MsgBox SQLSessionDate

    What is the result in the msgbox ?
    Francois

  5. #5
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Date variable in SQL (2002)

    Thank you everyone - I found the problem - some idiot (me) had declared the variable SQLSessionDate as date instead of string.

Posting Permissions

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