Results 1 to 4 of 4
  1. #1
    George is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    295

    Filtering using variable parameter


    Good Morning,

    Using the following filter works fine

    Student.Filter = "[Class ID]= 270"

    But when replaced by the following it does not work:

    p = 270

    Student.Filter = "[Class ID]= p"

    The error message is: 3061 "Too few parameters. Expected 2.

    These codes look identical I wonder why the second one dosen't work.

  2. #2
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    When you enclose something in double quotes it is a string.

    They are not identical to access

    one reads:
    Student.Filter= "[Class ID]=270"
    the other reads
    Student.filter="[Class ID]=p"
    despite the variable P having a value, because it has been delimited as a string it becomes simply the letter p.

    You need to concatenate it to the end of the string using &.

    The correct syntax should be
    Student.filter= "[class id]=" & p

    T

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If you looked at the filter property immediately after setting the filter, you would see the letter "p" instead of the number 270.
    The filter will work if you concatenate the variable "p" like this:

    p = 270
    Student.Filter = "[Class ID]= " & p

  4. #4
    George is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    295

    Problem Solved

    Thanks Steve. You are great.

    I dont know how to mark it as solved

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

Similar Threads

  1. Filtering Blanks, Report Parameter
    By leamas in forum Reports
    Replies: 1
    Last Post: 05-17-2012, 12:07 PM
  2. Replies: 0
    Last Post: 08-10-2011, 11:59 AM
  3. Problem with filtering on DATE Variable
    By SIGMA248 in forum Programming
    Replies: 1
    Last Post: 04-01-2011, 10:33 AM
  4. Replies: 7
    Last Post: 12-29-2010, 04:07 PM
  5. Variable from Parameter Query
    By OldCityCat in forum Programming
    Replies: 4
    Last Post: 08-23-2010, 11:25 AM

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