Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264

    Unanswered: Refer to List box column by name

    Is there a way to refer to a column in a list box by name rather than using something like listbox.column(0,2)?

    I would like to be able to access it by the column heading, similar to what you would do with a recordset. rs!fieldName

    The list box is created from a table and I access specific columns in the list box in several places in the code. I am concerned about the stability of the code if someone alters the table.

    Any ideas?

    Steve

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    No. Listbox columns do not have names.

    You could use a goofy work around by including column "names" in the listbox, which essentially sets (x, 0) to the "name" of the field. Then iterate through the columns in the listbox to pull all of the column names into an array. You could then reference this array to find columns by name and dump the values into variables which could be called as though they were column names.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by Teddy
    No. Listbox columns do not have names.

    You could use a goofy work around by including column "names" in the listbox, which essentially sets (x, 0) to the "name" of the field. Then iterate through the columns in the listbox to pull all of the column names into an array. You could then reference this array to find columns by name and dump the values into variables which could be called as though they were column names.
    A.K.A. an enumeration ... And Ted's right it's "goofy" if the columns/data are not likely to change ... It does have value for readability and updateability (you change the column in only 1 place) ...
    Back to Access ... ADO is not the way to go for speed ...

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Quote Originally Posted by M Owen
    A.K.A. an enumeration ...
    You and your fancy-pants terminology. Damn cake eaters.




















    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Aug 2004
    Posts
    13

    Variable

    If you refer to that list box on a consistant basis then you could Declare a variable and set it equal to it.

    have fun

  6. #6
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by Teddy
    You and your fancy-pants terminology. Damn cake eaters.
    What's the good of "fancy pants" terminology if you can't use it ... I'm a cake eater? Haven't had it in years ... Well except for cheese cake - but that doesn't count.
    Back to Access ... ADO is not the way to go for speed ...

  7. #7
    Join Date
    Aug 2004
    Posts
    13
    If for some reason you need to change the Name or column being referenced it is easier to change the ONE time the variable is set to, than scroll though different sections of code and hope you get them all.

  8. #8
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    Quote Originally Posted by bigfoot0017
    If you refer to that list box on a consistant basis then you could Declare a variable and set it equal to it.

    have fun
    Could you elaborate on this, I am not clear what you are suggesting.

    Steve

  9. #9
    Join Date
    Aug 2004
    Posts
    13
    Something like this

    Dim varCombo as variant ' in your declorations section

    set varCombo = listbox.column(0,2)

    Just my thought. Although when working with VBA there are many ways to achieve the same objective. But keep in mind you want simplicity, and readability! Who knows when or who may have to go back and edit your code in the future.

Posting Permissions

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