Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2008
    Posts
    78

    Unanswered: Simple Combo Box Question

    I have a combo Box being populated by a table in a form. I want to capture the users choice. When they press the button after choosing from the combo box I look at :

    rptChoice.Value

    Where rptChoice is the combo box.

    This seems to return an integer, like an index to the choice selected. Meaning, first choice (return 1), second choice (return 2).

    I'd like to get the actual value the user chose. I could do a case structure on 1, 2,3 etc.. but my code would be more readable if I could branch on something like

    9 AM Report
    Weekly Control Counts
    EOD Production Problem Roll UP

    which are the choices in the combo box.

    How can i get to the actual value, not the index?

    Thanks!

    I looked in the manual and looked at the sample combo box code in this forum but couldn't find it...

  2. #2
    Join Date
    Jun 2008
    Posts
    163
    I have a combo Box being populated by a table in a form
    Does that table have a numerical ID field? Try

    Forms!formname!rptChoice.column(1)

    Hope that helps.

  3. #3
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    it's not an index.
    in design view of your form, have a look at the properties of your combo (right-click if properties window is not visible).
    have a look at data/rowsource & boundcolumn
    then have a look at format/columncount & columnwidths

    it is important that you understand how combos work, so spend some time playing with this stuff.

    the "index" you are getting is the .boundcolumn (that is what combo .value returns) - so it is a value from the .rowsource query (...from your table). it runs 1, 2, 3 etc because that is what you have in your table.

    you have two choices.
    either
    rptChoice.column(N)
    where N is the index (this time it really is a zero-based index 0=first, 1=second etc) of the column in the combo .rowsource you want to talk to.
    or
    change the .boundcolumn in design view to the column you want to talk to (and here MS has been wonderfully inconsistent - the design view index is one-based 1=first, 2=second etc).

    izy
    currently using SS 2008R2

  4. #4
    Join Date
    Aug 2008
    Posts
    78
    I have two fields in the table, ID and Report. ID is 1,2,3,4 etc as the primary key.

    The bound column is 1 so now it makes sense that it's returning a 1, or 2,etc. It's returning the value that is bound to the combo box.

    Code:
    N = rptChoice.Value
    MsgBox "Stuff in combo box: " & N
    SomeText = rptChoice.Column(N)
    MsgBox "Stuff in combo box: " & SomeText
    SomeText = rptChoice.Column(rptChoice.Value)
    MsgBox "Stuff in combo box: " & SomeText
    Assume the user selects the 2nd choice, and "Weekly Control Counts" appear in the combo box.

    The first msgBox produces "Stuff in combo box: 2"
    The second msgBox produces "Stuff in combo box: Weekly Control Counts"
    The third msgBox produces "Stuff in combo box: Weekly Control Counts"

    If I understand correctly, the third message box is simply a coincidence that the ID happens to be the number 2, the second choice.

    Thanks for your help. Experimenting has given me a much better understanding. I could bind the comboBox to column 2 and have it return the report name directly.

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I could bind the comboBox to column 2 and have it return the report name directly.
    Provided the textual data isn't going to be stored in a numeric foreign key, then you could do that.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    If I understand correctly is not correct (LATER or maybe it is correct and I misread what you are saying)
    any 2 you are seeing on the second combo item is the ID field from your table.

    there is an inherent zero-based row-index in a combo (so if you were seeing the row-index it would be 1 for the second record).

    the row index can be useful - for example to select the first item in a combo from code:
    me.mycombo = me.mycombo.column(indexOfBoundColumn, 0)
    ..the 0 being the first row.

    izy
    Last edited by izyrider; 09-25-08 at 03:06.
    currently using SS 2008R2

Posting Permissions

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