Trying to do OpenRecordset and Getting a "Too Few Parameters" Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sleach
    New Member
    • Aug 2022
    • 1

    Trying to do OpenRecordset and Getting a "Too Few Parameters" Error

    The error i get is runtime error 3061. "Too few parameters. Expected 2.

    here is the code:
    Code:
    Private Sub Form_Load()
      
      Dim dbs As DAO.Database
      Dim TstVal As String
      Dim StrSQL As String
      Dim rsSql As DAO.Recordset
     
      Set dbs = CurrentDb
      
      TstVal = GetUserName()
        
      StrSQL = "SELECT * FROM Table_Employees WHERE TABLE_Empolyees.Emp_PC_User_Name = " & TstVal & "; "
      
     [u]Set rsSql = dbs.OpenRecordset(StrSQL, dbOpenSnapshot)[/u]
        
      If Not rsSql.EOF Then
        With rsSql
        Me.QryEmpNam = TABLE_Employees.EMP_Name
        End With
        Set Rs = Nothing
      End If
        
    End Sub
    The underscored line is the one that Debug breaks on.

    Any help would be great.
    Last edited by NeoPa; Aug 17 '22, 01:17 AM. Reason: Added mandatory [CODE] tags and updated italics to underscores for clarity.
  • isladogs
    Recognized Expert Moderator Contributor
    • Jul 2007
    • 483

    #2
    First of all you mistyped Table_Employees as TABLE_Empolyees . Fix that
    Secondly, assuming User_Name is a text field, then add single quotes as the text delimiter:
    Code:
    StrSQL = "SELECT * FROM Table_Employees WHERE TABLE_Employees.Emp_PC_User_Name =[B] '[/B]" & TstVal & "[B]'[/B]; "
    Last edited by isladogs; Aug 17 '22, 02:03 AM. Reason: Typo

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      Hi Sleach.

      Welcome to Bytes.com.

      I see that Colin (isladogs) has already shown you the specific problem with your SQL code.

      In future though, you may benefit from a better understanding of how to explore and find bugs in your own SQL. How to Debug SQL String is where you can find out how to do this simply and easily.

      Comment

      Working...