Query Select Error; Datetime in vb6 from db Ms.Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Octo Siburian
    New Member
    • Oct 2010
    • 19

    Query Select Error; Datetime in vb6 from db Ms.Access

    How do I interpret the declaration time 'AM' and 'PM' in Ms.access Query

    I have Query Select in vb6.0
    to get data from Ms.access database

    Code:
        SQLSelectdbRAS = "SELECT a.DN, b.DIN, c.PIN, c.UserName, b.Clock, d.ItemName " & _
                         "FROM ((ras_Device a INNER JOIN ras_AttRecord b ON a.DN=b.DN) " & _
                         "LEFT JOIN ras_Users c ON b.DIN=c.DIN) " & _
                         "LEFT JOIN ras_AttTypeItem d ON b.AttTypeId=d.ItemId " & _
                         "WHERE b.DIN=c.DIN AND Format(b.Clock, 'mm/dd/yyyy')=#" & _
                         Format(dateNow_, "mm/dd/yyyy") & "# AND " & _
                         "Format(b.Clock, 'mm/dd/yyyy hh:nn:ss')>=#" & _
                         Format(dateNow_, "mm/dd/yyyy 4:00:00PM") & "# AND " & _
                         "Format(b.Clock, 'mm/dd/yyyy hh:nn:ss')<=#" & _
                         Format(dateNow_, "mm/dd/yyyy 11:00:00PM") & "#"
        Debug.Print SQLSelectdbRAS
        Set rsFinger = da_GetRs(SQLSelectdbRAS)
    But when i run that query, i get this message error
    'Syntax error in date in query expression 'b.DIN=c.DIN AND Format(b.Clock, 'mm/dd/yyyy')=#10/19/2010# AND Format(b.Clock, 'mm/dd/yyyy hh:nn:ss')>=#10/19/2010 4:00:00P10# AND Format(b.Clock, 'mm/dd/yyyy hh:nn:ss')<=#10/19/2010 11:00:00P10#'.

    I want to interpret 4:00:00P10 in 4:00:00 PM and 11:00:00P10 in 11:00:00 PM

    Can anyone help me to fix that query?

    Regards,
    Octo
    Last edited by NeoPa; Oct 20 '10, 11:35 AM. Reason: Please use the [code] tags provided.
  • colintis
    Contributor
    • Mar 2010
    • 255

    #2
    for this formatting, it would be much simplier using this
    Code:
    "b.Clock BETWEEN #" & _
    Format(dateNow__, "mm/dd/yyyy 16:00:00") & _
    "# AND #" & _
    Format(dateNow__, "mm/dd/yyyy 23:00:00")
    By default, MS Access have full date/time as mm/dd/yyyy hh:mm:ss (in 24hr style) in SQL statements, so no necessary formatting needed to the table fields.

    Comment

    • Octo Siburian
      New Member
      • Oct 2010
      • 19

      #3
      Dear Colintis,

      Thank you so much for your help
      it's work..

      GBU always..

      Regards,
      Octo

      Comment

      Working...