Results 1 to 9 of 9

Thread: Date & ADO **RESOLVED**

  1. #1

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479

    Date & ADO **RESOLVED**

    Why does this not work?
    With Debug firstDate & lastDate are correct but the SQL statement does not return any values, and I know they are there.
    Please help.
    VB Code:
    1. Dim firstDate As Date
    2.         Dim lastDate As Date
    3.        
    4.         myChart.Row = 1
    5.         firstDate = myChart.RowLabel
    6.        
    7.         myChart.Row = myChart.RowCount
    8.         lastDate = myChart.RowLabel
    9.        
    10.         'Get and print history
    11.         cnnCon.Open dataText
    12.         rsRes.Open "SELECT Date, Result, SampleComments.Comment " & _
    13.                    "FROM SampleResults, SampleComments " & _
    14.                    "WHERE SampleResults.ID = SampleComments.ID " & _
    15.                    "AND SampleResults.TestName = " & Chr(34) & _
    16.                    cboTest.Text & Chr(34) & _
    17.                    " AND Date >= " & firstDate & _
    18.                    " AND Date <= " & lastDate & _
    19.                    " ORDER BY Date", _
    20.                    cnnCon, _
    21.                    adOpenKeyset, _
    22.                    adLockReadOnly, _
    23.                    adCmdText
    24.                    
    25.         With rsRes
    26.             If (Not (.BOF And .EOF)) Then
    27.                 .MoveFirst
    28.                 While (Not .EOF)
    29.                     Printer.Print "Date: " & .Fields("Date").Value & _
    30.                                   "  Result: " & .Fields("Result").Value & vbTab & _
    31.                                   "  Comment: " & .Fields("Comment").Value
    32.                     .MoveNext
    33.                 Wend
    34.             End If
    35.         End With
    36.        
    37.         rsRes.Close
    38.         cnnCon.Close
    Last edited by GlenW; Apr 8th, 2002 at 09:18 AM.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Try enclosing the dates withing # characters:
    VB Code:
    1. " AND Date >= #" & firstDate & _
    2. "# AND Date <= #" & lastDate & "#" '...the rest
    Best regards

  3. #3
    Si_the_geek
    Guest
    you need quotes or hashes around the dates, eg:

    VB Code:
    1. " AND Date >= '" & firstDate & _
    2.                    "' AND Date <= '" & lastDate & _
    3.                    "' ORDER BY Date", _
    or:
    VB Code:
    1. " AND Date >= #" & firstDate & _
    2.                    "# AND Date <= #" & lastDate & _
    3.                    "# ORDER BY Date", _

  4. #4

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    Nope, still doesn't work.
    Could it be confusing UK and US date formats?
    If yes how do I fix it?

  5. #5
    Si_the_geek
    Guest
    yep, common problem...
    VB Code:
    1. " AND Date >= #" & format(firstDate,"mm/dd/yyyy") & _
    2.                    "# AND Date <= #" & format(lastDate,"mm/dd/yyyy") & _
    3.                    "# ORDER BY Date", _

  6. #6

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    You are stars, Thanks a lot
    Works perfectly.

  7. #7
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    you could use the Int function

    i.e.

    WHERE Int(Date) <= int(Date2)

    etc, that would work.

    NOTE: The int function will chop off the decimals, thus chopping off the time part of the dates when comparing
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  8. #8

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    Originally posted by darre1
    you could use the Int function

    i.e.

    WHERE Int(Date) <= int(Date2)

    etc, that would work.

    NOTE: The int function will chop off the decimals, thus chopping off the time part of the dates when comparing
    What a good idea!!

  9. #9
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    Originally posted by GlenW

    What a good idea!!
    thanks!

    note that if you want to catch a date between two dates though you should add 1 to the end date, else it will only catch between 00:00:01 of the second date if you get my drift.

    i.e.

    Code:
    SELECT * FROM table WHERE Int(dtmDate) BETWEEN Int(Date1) AND Int(Date2) + 1; 
    'basically from 00:00:00 on date1 to 23:59:59 on date2
    'if you leave the +1 out it won't include the full day for date 2!
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

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