Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dates format (2000)

    I have a search form which has a date field. Person enters a date and a date variable records that date. A button then searches for all records that apply to that date.

    Big problem - The user enters 1 September 2000 and the variable records this as #1-9-2000# for the query. The problem is that the records searched are for January 9, not September 1. How can I resolve this?

    Here's the code I'm using:

    Dim datey as date, sqlstr as string, strg as string
    strg = "select * from contacts where "

    datey = Me.Date
    sqlstr = "[Date] between " & Chr(35) & datey & Chr(35) & " And " & Chr(35) & datey + 1 & Chr(35) & ""

    strg = strg & sqlstr
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset(strg)
    If rst.RecordCount = 0 Then
    MsgBox "There are no calls in the database that match this criteria.", vbOKOnly, "No Match"
    Exit Sub
    End If
    DoCmd.OpenForm "Phone", acNormal, , sqlstr
    end sub

    Thank you for your help!

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

    Re: Dates format (2000)

    In sql you have always to use US date formats.

    sqlstr = "[Date] between " & Chr(35) & Format(datey,'mm/dd/yyyy') & Chr(35) & " And " & Chr(35) & Format(datey + 1,'mm/dd/yyyy') & Chr(35) & ""
    Francois

  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dates format (2000)

    Thank you very much - you have prevented me from going bald!

Posting Permissions

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