Results 1 to 3 of 3

Thread: Fail to compare date retrieved from ACCESS with DateTimePicker

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Location
    Malaysia
    Posts
    2

    Unhappy

    here's my code:

    Set rs1 = adconn.Execute("SELECT * from ApplDetail where appr = true and level1 = false and apprdate >= " & DTPicker1.Value)

    apprdate is a date type data, in Access.
    however, i failed to compare it with my DateTimePicker's value... it doesn't return the expected result.
    the rs1 recordset is to be retrieved by a DataReport, so only SQL statements can be used...
    can you help me this time?
    thanks.
    Yih



  2. #2
    Lively Member Backbraker's Avatar
    Join Date
    Dec 2000
    Location
    Lummen, Belgium
    Posts
    117
    The problem probably is that you date from your db isn't the same format as the date from your dtpicker. You must make them the same format with the Format function :

    Dim tempDate as date

    tempDate = format(DTPicker1.value,"dd/mm/yy")

    Then your comparison...

    ' Off course the format must be the same as the format you use in Access. It could also be mm/dd/yy or something else.
    Breaker

    (VB 6.0 ENT SP3 WIN 2000 PROF)=> WORK
    (VB 6.0 ENT SP3 WIN ME)=> HOME -> Upgrade to .NET is coming

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    lingtze, it because you miss out the "#" sign. For date in database, you must include the "#" at both end of the Date datatype.

    Code:
    Set rs1 = adconn.Execute("SELECT * from ApplDetail where appr = true and level1 = false and apprdate >= #" & DTPicker1.Value & "#);"

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