title: VBA Code for an Update button on a form
body: <p>I have a form that has an unbound combobox (cboJack) and 7 Unbound Text Fields (txtID, txtSwitch, txtPortNumber, txtVoiceVLAN, txtdataVLAN, txtCableNumber, txtcomments3)</p>
  
  <p>Whenever I choose an option from the combobox, the 7 text fields are autopopulated through the use of the following code:</p>
  
  <pre><code>Private Sub cboJack_Change()
  Me.txtID = Me.cboJack.Column(0)
  Me.txtSwitch = Me.cboJack.Column(2)
  Me.txtPortNumber = Me.cboJack.Column(3)
  Me.txtVoiceVLAN = Me.cboJack.Column(4)
  Me.txtdataVLAN = Me.cboJack.Column(5)
  Me.txtCableNumber = Me.cboJack.Column(6)
  Me.txtComments3 = Me.cboJack.Column(7)
  End Sub
  </code></pre>
  
  <p>I have created an update button on the form so that after I select value from the combobox and everything autopopulates, I can edit whatever fields I want, and then press the update button to save everything. Some of the fields are number fields and some are text fields. For some reason I'm getting a syntax error. Here is the code I have for my command button.</p>
  
  <pre><code>Private Sub cmdUpdate_Click()
  Dim strSQL As String
  
  strSQL = "UPDATE Switches SET Switch = '" &amp; Me.txtSwitch &amp; "', [Port Number] = " &amp; Me.txtPortNumber &amp; ", [Voice VLAN] = " &amp; Me.txtVoiceVLAN &amp; ", [Data VLAN] = " &amp; Me.txtdataVLAN &amp; ", [Cable Number] = " &amp; Me.txtCableNumber &amp; ", [Comments] = '" &amp; Me.txtComments3 &amp; "' WHERE Jack = '" &amp; Me.cboJack &amp; "'"
  
  DoCmd.RunSQL (strSQL)
  End Sub
  </code></pre>
  
  <p>The number type columns are, Port Number, Voice VLAN, DataVLAN and Cable Number. ID is autonumber, and the rest are text columns.</p>
  
  <p>I think the reason why there's a problem is that some of the fields in Port Number, Voice VLAN, data VLAN and Cable Number don't have any values (Some of the values are null)</p>
  
  <p>Any suggestions on how to fix this?</p>
  
  <p>Thanks in advance.</p>