Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2009

    Unanswered: How do I set the value of the combo box and not the index?

    HI. I've got a combo box based on a table with ID as the first field.

    I know the ID I want, and want to set the combo box to that.

    I use Forms!Formname.cmbBoX = ID, and what this does is set the combo box to the record at the index = ID.

    So instead of trying to find a match for that ID, it uses the number as an index position and jumps to that index.

    I've also tried "'" & ID "'" (to try send ti a string instead) but same thing happens. The combo is bound by the ID field so this should work.

    Any ideas?

  2. #2
    Join Date
    Jun 2009
    hmm, was playing around and thought I'd change the bound column.

    Apparently if I Bind to Column 0, it binds to the index, and binding to column 1 uses the first column, my ID field.

    Strange, as if I do [cmbProperty].[Column](1), I get the second column!

    Isnt this a bit misleading?

  3. #3
    Join Date
    May 2004
    New York State
    Welcome to the vagaries of the combo box. Some of the Column properties start with 1, such as the ColumnCount and the BoundColumn properties. Others start with 0, such as the Column property.

    Don't be shy about using the Help files. They spell it all out.


  4. #4
    Join Date
    Dec 2004
    Madison, WI
    Yes. It is very misleading (and one of the things about comboboxes/listboxes that bugs me).

    me!MyCombobox = the 1st column in the combobox rowsource.
    me.MyCombobox.column(1) = the 2nd column in the combobox rowsource
    and so on....

    I will typically keep the 1st column the bound column and just use me!MyCombobox to reference the value of the combobox that's returned (I'll set the column width to 0" for this column so it doesn't show when typed into the combobox.)

    You may want to do a: msgbox me!MyCombobox or msgbox me.myCombobox.column(1) in your AfterUpdate event of the combobox to see what value it's really returning (keeping in mind that the BoundColumn # is the one you want.)

    As Sam Landy pointed out, you may want to research the MSAccess help on this. There are some good help examples.

    Also note: there are several 'search' type examples in the code bank which demonstrate using comboboxes/listboxes. You may want to check these out to see how they work.
    Last edited by pkstormy; 11-24-09 at 15:53.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

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