CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Sort By Date

  1. #1
    Join Date
    Feb 2001
    Posts
    29

    Sort By Date

    Hi,

    I have an access DB with a field (MailDateSent), I want to sort between 2 dates, my code below is not working.

    Any help appreciated.

    Regards,

    Alan.

    Date1 = txtDate1.Text
    Date2 = txtDate2.Text

    'SQL = "SELECT * FROM Customers WHERE (MailDateSent) >= Date1 and (MailDateSent) <= Date2 ORDER bY CompanyName"

    Set Customers = DB.OpenRecordset(SQL, dbOpenDynaset)



  2. #2
    Join Date
    Apr 2001
    Location
    CA
    Posts
    153

    Re: Sort By Date

    I'm using SQL-Server so this may not be the right syntax for you, but I always have to put single quotes around dates.

    SQL = "SELECT * FROM Customers WHERE (MailDateSent) >= '" & Date1 & "' and (MailDateSent) <= '" & Date2 & "' ORDER bY CompanyName"


    thanx/good luck,
    adam
    thanx/good luck

  3. #3
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Sort By Date

    In access you use the pound sign.

    SQL = "SELECT * FROM Customers WHERE (MailDateSent) >= #" & Date1 & "# and (MailDateSent) <= #" & Date2 & "# ORDER bY CompanyName"

    David Paulson

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

Featured