Results 1 to 4 of 4
  1. #1
    jhrBanker is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2009
    Posts
    68

    Execute, "Too few parameters", "Expected 2"

    Access 2007 db: Two text fields on a form contain existing value and new value. When the user clicks the form button, an update query should run to change the table field value. A text field on the form should indicate the number of records that were updated (txtAudForecast = db.RecordsAffected). However, the code is generating the error: Too few parameters. Expected 2.
    Here's the code:

    Private Sub cmdAudForecast_Click()
    On Error GoTo Err_cmdAudForecast_Click

    Dim db As Database
    Dim sqlChgTo As String
    Dim sqlChgFm As String
    sqlChgTo = [Forms]![frmMainMenu]![txtChgTo]
    sqlChgFm = [Forms]![frmMainMenu]![txtChgFrom]
    Set db = CurrentDb()
    MsgBox "Change " & sqlChgFm & " To " & sqlChgTo
    'DoCmd.SetWarnings False
    db.Execute "UPDATE audForecast " & _
    "SET audForecast.audUser = sqlChgTo " & _
    "WHERE (((audForecast.audUser)= sqlChgFm));"

    'DoCmd.SetWarnings True

    lblAudForecast.Visible = True


    txtAudForecast = db.RecordsAffected
    Exit_cmdAudForecast_Click:
    Exit Sub

    Err_cmdAudForecast_Click:
    MsgBox Err.Description
    Resume Exit_cmdAudForecast_Click
    End Sub

    Any help will be appreciated.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Do not enclose variables in quotes. Concatenate.

    "SET audForecast.audUser = " & sqlChgTo & _
    "WHERE audForecast.audUser = " & sqlChgFm & ""

    Is audUser a number type field? If it is text, need apostrophe delimiters:

    "SET audForecast.audUser = '" & sqlChgTo & "'" & _
    "WHERE audForecast.audUser = '" & sqlChgFm & "'"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You have to concatenate the variables:
    Code:
    Private Sub cmdAudForecast_Click()
        On Error GoTo Err_cmdAudForecast_Click
    
        Dim db As DAO.Database
        Dim sqlChgTo As String
        Dim sqlChgFm As String
    
        Set db = CurrentDb()
    
    
        sqlChgTo = [Forms]![frmMainMenu]![txtChgTo]
        sqlChgFm = [Forms]![frmMainMenu]![txtChgFrom]
        MsgBox "Change " & sqlChgFm & " To " & sqlChgTo
        'DoCmd.SetWarnings False
        db.Execute "UPDATE audForecast " & _
                   "SET audForecast.audUser = " & sqlChgTo & _
                   "WHERE (((audForecast.audUser) = " & sqlChgFm & "));"
    
        lblAudForecast.Visible = True
        txtAudForecast = db.RecordsAffected
    
    Exit_cmdAudForecast_Click:
        Exit Sub
    
    Err_cmdAudForecast_Click:
        MsgBox Err.Description
        Resume Exit_cmdAudForecast_Click
    
    End Sub
    What June said.....
    Last edited by ssanfu; 10-30-2014 at 02:09 PM. Reason: June was faster...

  4. #4
    jhrBanker is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2009
    Posts
    68
    That did it! Many thanks. Muchly appreciated.

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

Similar Threads

  1. Replies: 1
    Last Post: 09-03-2014, 03:27 AM
  2. Replies: 8
    Last Post: 07-15-2014, 05:56 PM
  3. Export "Query or Report" to a "Delimited Text File"
    By hawzmolly in forum Import/Export Data
    Replies: 3
    Last Post: 08-31-2012, 08:00 AM
  4. Replies: 11
    Last Post: 03-29-2012, 02:32 PM
  5. Replies: 16
    Last Post: 07-22-2011, 09:23 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