Results 1 to 6 of 6
  1. #1
    JackLeon is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2015
    Posts
    15

    Help with sql query in Access 2007

    I had been using the following query since a while in my access form and it was working fine till now.. but now I am getting error "Too few parameters. Expected 1"



    sqlGrpCd = "SELECT Group_Id FROM Tbl_Payment_Group Where Trim(Eff_Dt) <> '' and Exp_Dt >= " & Date & " ORDER BY Group_Id DESC"
    Set rsGrpCd = CurrentDb.OpenRecordset(sqlGrpCd, dbOpenSnapshot)

    On further analyzing, I found that the query piece "and Exp_Dt >= " & Date & "", is the cause for error. The Date comes out as '15-Oct-15' and the query on execution, looks like:

    select Group_Id from Tbl_Payment_Group where trim(eff_dt) <> '' and Exp_Dt >= 15-Sep-15 order by Group_Id Desc

    Table Data looks like:
    Group_Id: Rate: Eff_Dt: Exp_Dt
    G1: 1100: 01-Oct-15: 30-Dec-15

    and Table structure as:
    Group_Id - Text
    Rate - Number
    Eff_Dt - Date/Time
    Exp_Dt - Date/Time

    Please advice. TIA.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Either move the Date function inside the quotes or surround the value with #.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    JackLeon is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2015
    Posts
    15
    Thanks bro, it worked!! But what will still trouble me is that I did this code around 2 years back and have been using it since then but it never gave me any trouble till now.. the only change I see, from the last time I accessed my application, is, that I upgraded my operating system to Win 10.

    anyway, thanks a lot for your help

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help! I'm surprised it worked as it was.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    JackLeon is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2015
    Posts
    15
    Yup, confirmed. It has to be Win 10.. tried the same code on my other machine with Win 7 and it worked fine. It seems, that encasing Date field with a # was not mandatory earlier but with the new upgrade, it will have to be done anyhow.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Interesting. Maybe your format let you get away with it. # has always been required with dates like 9/16/2015.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 06-05-2015, 10:00 AM
  2. Ranking Query in Access 2007
    By DJ Rhino in forum Access
    Replies: 11
    Last Post: 03-05-2015, 06:08 AM
  3. Replies: 1
    Last Post: 02-04-2013, 05:52 PM
  4. Replies: 2
    Last Post: 06-18-2011, 09:55 AM
  5. MS Access 2007 Query Help
    By tjames in forum Queries
    Replies: 2
    Last Post: 12-15-2010, 08:06 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums