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

    [2008] Date parameter in MS Access WHERE clause - Can you show me the syntax?

    Greetings Everyone,

    In the TableAdapter configuration wizard I am using this query:

    Code:
    SELECT        AttendanceID, StudentID, ClassId, DateOfClass, Absent
    FROM            Attendance
    WHERE        (DateOfClass BETWEEN #5/1/2010# AND #5/30/2010#)
    Can you tell me the correct syntax to change the #5/1/2010# AND #5/30/2010# so the WHERE clause uses dteStartDate AND dteStartDate which are date variables ?

    I tried this but it tells me I need to use the to_date function. dteStartDate is already a date variable so I know my syntax is wrong.

    Code:
    SELECT        AttendanceID, StudentID, ClassId, DateOfClass, Absent
    FROM            Attendance
    WHERE        (DateOfClass BETWEEN #" & dteStartDate & "# AND #" & dteEndDate & "#)
    Thanks.

    Truly,
    Emad

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: [2008] Date parameter in MS Access WHERE clause - Can you show me the syntax?

    Good question. I would think the format you tried would work in the case where you are using string variables.

    Using date variables I would try omitting the # signs and see what happens.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: [2008] Date parameter in MS Access WHERE clause - Can you show me the syntax?

    or something like this:

    Code:
    WHERE        (DateOfClass BETWEEN " & CDate(dteStartDate) & " AND " & CDate(dteEndDate))
    Might need the second parameter to format it the way the DB is expecting it
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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