Results 1 to 4 of 4
  1. #1
    Join Date
    May 2012
    Posts
    33

    Unanswered: store combobox selection in table

    Hi. I have a combobox that look up from a table. Then I like the selection made in combobox to store this in another table. The problem i facing is that it stores just the ID of the combo selection in the table and not the text showed in combobox. How to set this correct:

    This is what I have in combobox row source:

    SELECT PersonalContact.ID, PersonalContact.Abbreviation
    FROM PersonalContact
    ORDER BY PersonalContact.Abbreviation;

    Thanks!

  2. #2
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5

    ComboBox Issue resolve

    where cboCombo is the name of your combo box, tblMytable = your table name

    On the AfterUpdate event of the combo box or behind a button

    Dim strCombo as string
    Dim rst as recordset

    set rst = currentdb.openrecordset("select * from tblMytable", dbopendynaset)

    strCombo = me.cboCombo.column(1) 'This is the 2nd column of your row source - 'the index starting at 0 for column 1

    rst.addnew
    rst!MyFieldforComboboxValue = strCombo
    rst!otherfields = OtherValues
    rst.update

    That will add a new record in your table to
    to update the comb obx value in an existing record

    Currentdb.execute "Update tblMytable Set myfield = " & "'" & strcombo & "'" & " " _
    & "where [somefield in your table ] = [some criteria]"
    Dale Houston, TX

  3. #3
    Join Date
    May 2012
    Posts
    33
    Isent it another simpler way? I manage to store the ID of the combo selection (table). As mention I like to store the other column of the combo table.

    So the combo table has 2 columns. ID and Name. It is the Name that is displayed and selected in combo. I like to store the Name in the main table. But it stores the ID when I select. I have no event so far to do this so I imagine it is a simple properties or query setup. Ex in the row source properties of combobox.

  4. #4
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5
    What ever code you are using to store the id just use the syntax combobox.column(1)
    THAT WILL GRAB THE DATA THAT YOU ARE SEEING IN THE COMBOBOX. But that data is a string where as the id column is an integer - if you want to save that string data thwe same way you are saving the id data then you may get a data type error - the way I explained it to you - based on the minimal information you have given me - is the best most professional way to do this.
    Dale Houston, TX

Posting Permissions

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