title: Acess VBA - Update Variable Column (Too few parameters error)
body: <p>I am new to VBA in Access database, the following code tries to combine two columns in Table_2, but one of the column name needs to be defined by a field value from Table_1, I tried to run the code, but it returns "Error updating: Too few parameters. Expected 1." I am not sure where is the problem. </p>
  
  <p>Appreciate if someone can help. Thanks a lot.  </p>
  
  
  
  <pre class="lang-vb prettyprint-override"><code>Function test()
  On Error Resume Next
    Dim strSQL As String
    Dim  As String
    Dim  txtValue As String
    txtValue = Table_1![Field_A]
  
    Set ws = DBEngine.Workspaces(0)
    Set db = ws.Databases(0)
  
  On Error GoTo Proc_Err
    ws.BeginTrans
  
    strSQL = "UPDATE Table_2 INNER JOIN Table_1 ON Table_2.id = Table_1.id SET Table_2.Field_Y = Table_2!txtValue &amp; Table_2![Field_Z]"
    db.Execute strSQL, dbFailOnError
  
    ws.CommitTrans
  
  Proc_Exit:
    Set ws = Nothing
    Set db = Nothing
    Exit Function
  
  Proc_Err:
    ws.Rollback
    MsgBox "Error updating: " &amp; Err.Description
    Resume Proc_Exit
  End Function
  </code></pre>
  
  <p><strong>UPDATE:</strong> The following codes are with actual field names:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Function CombineVariableFields()
  On Error Resume Next
  
    Dim ws As Workspace
    Dim strSQL As String
    Dim fieldname As String
    fieldname = Table_1![SelectCombineField]
  
    Set ws = DBEngine.Workspaces(0)
    Set db = ws.Databases(0)
  
  On Error GoTo Proc_Err
    ws.BeginTrans
  
    strSQL = "UPDATE Table_2 INNER JOIN Table_1 ON Table_2.BookType = Table_1.BookType SET Table_2.CombinedField = [Table_2]!fieldname &amp; [Table_2]![BookName]"
    Debug.Print strSQL
    db.Execute strSQL, dbFailOnError
  
    ws.CommitTrans
  
  Proc_Exit:
    Set ws = Nothing
    Exit Function
  
  Proc_Err:
    ws.Rollback
    MsgBox "Error updating: " &amp; Err.Description
    Resume Proc_Exit
  End Function
  </code></pre>
  
  <p><strong>Below are screenshots of the two tables</strong></p>
  
  <p><a href="https://i.stack.imgur.com/juSmQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/juSmQ.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/xWY7E.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xWY7E.jpg" alt="enter image description here"></a></p>