Results 1 to 4 of 4

Thread: [RESOLVED] Dates and SQL again

  1. #1

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Resolved [RESOLVED] Dates and SQL again

    Firstly, I have read the new FAQ's about dates that si_the_geek posted a couple of days ago, but I am still having problems:

    I have made sure that the dates in the SQL statement have been converted to strings, by using the Format function.
    I have also changed them to use the ISO format (YYYY/MM/DD).

    I don't get an error with the actual SQL statement when I write it, but I get the error:

    Data type mismatch in criteria expression

    on the line rs.Open ....

    Code:
    'add new SQL statement to add SELECTED records
    strSQL = "SELECT * FROM tbl_Finances"
    strSQL = strSQL & " Where Finance_Date >= '" & Format(BetweenDate(0), "yyyy,mm,dd") & "'"
    strSQL = strSQL & " And Finance_Date <= '" & Format(BetweenDate(1), "yyyy/mm/dd") & "'"
    strSQL = strSQL & " ORDER BY Finance_Date"
    
    rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
    BetweenDate() As Date

    Quote Originally Posted by Debug.Print
    SELECT * FROM tbl_Finances Where Finance_Date >= '2007,07,01' And Finance_Date <= '2007/08/31' ORDER BY Finance_Date
    UK Date:
    01/07/2007
    31/08/2007
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  2. #2

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Dates and SQL again

    Answered this myself!

    Althought Format makes the value a string, it still needs the '#' surrounding the value, not the ' that strings need.

    Code:
    'add new SQL statement to add SELECTED records
    strSQL = "SELECT * FROM tbl_Finances"
    strSQL = strSQL & " Where Finance_Date >= #" & Format(BetweenDate(0), "yyyy,mm,dd") & "#"
    strSQL = strSQL & " And Finance_Date <= #" & Format(BetweenDate(1), "yyyy/mm/dd") & "#"
    strSQL = strSQL & " ORDER BY Finance_Date"
    
    rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Dates and SQL again

    Quote Originally Posted by aikidokid
    Answered this myself!

    Althought Format makes the value a string, it still needs the '#' surrounding the value, not the ' that strings need.
    IF it's Acces, then yes.... otherwise, most other DBMS will allow a date to be passed as a string, and it'll convert it to a Date type.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: [RESOLVED] Dates and SQL again

    Thanks tg, and yes, it is Access
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

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