Consulting

Results 1 to 3 of 3

Thread: Run-Time error '3061' Too Few parameters. expected 2 and 3

  1. #1

    Run-Time error '3061' Too Few parameters. expected 2 and 3

    For the life of me I can't figure this out. Can someone explain what I get this error? Here is the exact info of everything below.


    Table Name: Customer
    ID FirstName LastName
    1 Derek Welton
    3 Mark Welton


    Here is the code:
    strSQL = "SELECT Customer.ID, Customer.FirstName, Customer.LastName FROM Customer;"
    Set rs2 = CurrentDb.OpenRecordset(strSQL)
    
    
    Debug.Print strSQL
    
    
    Debug.Print txtFirstName.Value
    Debug.Print txtLastName.Value
    
    
    rs2.Filter = "[FirstName] = " & txtFirstName.Value
    Set rs2Filtered = rs2.OpenRecordset
    
    
    customerName = rs2Filtered.Fields("ID")
    Debug.Print customerName
    rs2.Close
    rs2Filtered.Close

    The output of the debugs are:
    SELECT Customer.ID, Customer.FirstName, Customer.LastName FROM Customer;
    Derek
    Welton

    This is the line that brings up error: Run-Time error '3061' Too Few parameters. expected 2
    Set rs2Filtered = rs2.OpenRecordset

    What I was trying to do before is filter 2 items, FirstName and LastName, but tried to debug by doing one filter:
    'used for debugging by filtering one item, produces "Expected 2"
    rs2.Filter = "[FirstName] = " & txtFirstName.Value 
    
    
    'original code, produces "Expected 3"
    rs2.Filter = "[FirstName] = " & txtFirstName.Value & " AND [LastName} = " & txtLastName.Value
    The original produces Run-Time error '3061' Too Few parameters. expected 3. The point of this code is to filter down to one record in order to grab the ID value and store it into "customerName". Any help would be appreciated!!

  2. #2
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    Names are text. Text requires quotes

    rs2.Filter = "[FirstName] = '" & txtFirstName.Value & "'"

  3. #3
    Thats right! I forgot that the format between text and numbers is different when it comes to filtering. Thank you very much. I appreciate your time going through my code.

Posting Permissions

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