Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2015
    Posts
    1

    Cool Unanswered: Table Update from a ComboBox Selection

    I have a form which uses a bound combo box, to a table "Offices", field Office. The selection of the office from the combo box should populate a table, "Selection", field "Office". I have create an update event for the combo box value to update the "Selection" table which is not working. The combo box works fine. Both Office.Office and Selection.Office are formatted as Text (255).

    Below is the code used for updating the table:


    Private Sub OfficeCombo_AfterUpdate()

    Dim strSQL As String
    strSQL = "UPDATE tbl_Selection_Variables SET Office = Me.OfficeCombo.Column(1).value"
    CurrentDb.Execute strSQL

    End Sub

    Any suggestions?

    Allan

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try:
    a) IF [Office] is defined as Text:
    Code:
    Private Sub OfficeCombo_AfterUpdate()
    
    Dim strSQL As String
    strSQL = "UPDATE tbl_Selection_Variables SET Office = '" & Me.OfficeCombo.Column(1) & "';"
    CurrentDb.Execute strSQL
    
    End Sub
    b) IF [Office] is defined as Numeric:
    Code:
    Private Sub OfficeCombo_AfterUpdate()
    
    Dim strSQL As String
    strSQL = "UPDATE tbl_Selection_Variables SET Office = " & Me.OfficeCombo.Column(1) & ";"
    CurrentDb.Execute strSQL
    
    End Sub
    Notes:
    1. Don't forget that Column(1) is the second column of the combo, Column(0) being the first (leftmost) one.
    2. The Column() member of a Combobox control does not have any Value property, Combo.Column(x) and not Combo.Column(x).Value.
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •