Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Feb 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help! -- VBA ListObject (VBA)

    I am new to VBA and have been trying to make a fairly straighforward selection form. I have a ListBox object on the form that I have populated with a list of diagrams. However, I need to be able to use a selected list object as an object and not just a string. How can I populate the ListBox with objects? I have seen many references to the .ItemData property to use as an index to synchronize to a Collection index. However, I do not have the .ItemData property available in VBA!

    This is basically what I am trying to do:

    ListForm.ObjectListBox.AddItem iDiag.Name '<-- Here is where I would like to add the ID of the item iDiag.ddId
    ' --> this does not work --> ListForm.ObjectListBox..ItemData(ListForm.ObjecLis tBox.NewIndex) = iDiag.ddId
    ' I am creating a collection with an index to the object
    diagCollection.Add iDiag, iDiag.ddId

    It would be great if I could just add the object to ListObject and set the ListObject Name separately. It seems that VB6 has this with the .Add() method.

    Any help is greatly appreciated! BTW, I would search this forum more thoroughly, but I do not see a search function available. So, if you point me to a thread, can you also point out how to search?

    Thx, Bill

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Help! -- VBA ListObject (VBA)

    Welcome to Woody's Lounge!

    The Lounge "menu bar" has a search button - see screenshot below. Also see <!help=09>Help 09<!/help>.

  4. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Help! -- VBA ListObject (VBA)

    UserForm list boxes don't have an ItemData or ListObject property, and they cannot contain objects, only strings.

    You can use an array or collection to hold objects, and use the ListIndex property of the list box as an index into the array, or the list item itself as the index into the collection.

  5. #4
    New Lounger
    Join Date
    Feb 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help! -- VBA ListObject (VBA)

    Thx. The search function was nestled along the top and I just missed it.

    As for ListObject, are there other controls that would be better? I can see that someone prior to me on this project has used a ListView object, but I do not see this control in the Toolbox. I am assuming he has used an add-in or some other library, but I cannot see where he loads the library (include?) or how I can reference the same type of control for my purposes.

    Thx, Bill

  6. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Help! -- VBA ListObject (VBA)

    The ListView control is not in the standard set of controls, but you can add it:
    - Right-click the Toolbox and select More Controls... from the popup menu.
    - Tick the check box for Microsoft ListView Control 6.0 (SP6).
    - Click OK.
    - ListView will be added to the controls in the Toolbox.
    - When you place a ListView on your userform, the first item in the Properties pane will be (Custom). This is used to set the properties specific to the ListView.
    - A reference to the appropriate library (Microsoft Windows Common Controls 6.0) will be set automatically.

  7. #6
    New Lounger
    Join Date
    Feb 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help! -- VBA ListObject (VBA)

    Thank you. I have gotten the ListView to work as I needed. I am using the .tag property to store my object. Just a bit of getting used to this environment is all...

Posting Permissions

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