Results 1 to 5 of 5
  1. #1
    hfreedman1957 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2017
    Posts
    35

    Too few parameters error on CurrentDb.OpenRecordset

    Here is my code. The statement in red is throwing the too few parameters error. STO1Name is in the current form where this event code is being launched. STOName is in the table tblSTOs being selected. The four DeploymentResource fields are also in tblSTOs being selected. I added the Me.Dirty statement and the Dim qdf As DAO.QueryDef only because they were in a code snippet I have that works. I'm a somewhat a newbie. Please help. Thanks!

    Private Sub STOName1_Exit(Cancel As Integer)
    Dim rs As Recordset
    Dim qdf As DAO.QueryDef
    Dim strSQL As String


    If STO1Name <> "" Then
    If Me.Dirty Then Me.Dirty = False
    strSQL = "SELECT STOName, DeploymentResource1, DeploymentResource2, DeploymentResource3, DeploymentResource4 FROM tblSTOs WHERE STOName = STO1Name;"
    Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
    If rs!DeploymentResource1 <> "" Then


    STO1Res1Name = rs!DeploymentResource1
    If rs!DeploymentResource2 <> "" Then
    STO1Res2Name = rs!DeploymentResource2
    If rs!DeploymentResource3 <> "" Then
    STO1Res3Name = rs!DeploymentResource3
    If rs!DeploymentResource1 <> "" Then
    STO1Res4Name = rs!DeploymentResource4
    End If
    End If
    End If
    End If

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    It needs to be in quotes:
    "... WHERE STOName = '" & Me!STO1Name & "';"

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You need to concatenate the of the control STO1Name VALUE to the SQL Where clause.
    Code:
    Private Sub STOName1_Exit(Cancel As Integer)
        Dim rs As DAO.Recordset
        Dim strSQL As String
        '    Dim qdf As DAO.QueryDef
    
        If Me.STO1Name <> "" Then
            If Me.Dirty Then
                Me.Dirty = False
            End If
            
            strSQL = "SELECT STOName, DeploymentResource1, DeploymentResource2, DeploymentResource3, DeploymentResource4"
            strSQL = strSQL & " FROM tblSTOs"
            strSQL = strSQL & " WHERE STOName = '" & Me.STO1Name & "';"
            
            Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
            If rs!DeploymentResource1 <> "" Then
                Me.STO1Res1Name = rs!DeploymentResource1
                If rs!DeploymentResource2 <> "" Then
                    Me.STO1Res2Name = rs!DeploymentResource2
                    If rs!DeploymentResource3 <> "" Then
                        Me.STO1Res3Name = rs!DeploymentResource3
                        If rs!DeploymentResource1 <> "" Then
                            Me.STO1Res4Name = rs!DeploymentResource4
                        End If
                    End If
                End If
            End If
        End If
    
        rs.Close
        Set rs = Nothing
    End Sub

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I'm a somewhat a newbie. Please help. Thanks!
    Then I'll point out that the first solution should work if the value is numeric and the second if it is text. To mix the methods otherwise would create an error (probably data type mismatch). Also, the error you posted can be caused by trying to run a stored query that requires parameters that are defined in the query, or if trying to run a stored query by passing parameters to it (where either of these methods are being done via code). When you build your own sql on the fly, it's not usually a problem.
    Last edited by Micron; 05-12-2017 at 04:06 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    hfreedman1957 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2017
    Posts
    35
    Thanks everyone!!! it worked like a charm. I think the 1st two were similar. I broke up the sql string assignment into 3 parts and used the single quotes as demonstrated. Added a refresh statement as well all is good. Thanks so very much!!! Greatly appreciated!

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

Similar Threads

  1. Too Few Parameters on .OpenRecordset()
    By Voodeux2014 in forum Forms
    Replies: 9
    Last Post: 01-28-2016, 04:45 PM
  2. Error in CurrentDb.Execute
    By Stefan Moser in forum Access
    Replies: 5
    Last Post: 04-17-2015, 01:38 PM
  3. Replies: 12
    Last Post: 09-04-2014, 10:53 PM
  4. Replies: 7
    Last Post: 07-24-2013, 02:01 PM
  5. Replies: 8
    Last Post: 12-21-2011, 12:50 PM

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