?
Solved

Combo Boxes

Posted on 2000-03-21
2
Medium Priority
?
202 Views
Last Modified: 2010-05-02
Hi,

How do I populate combo boxes with items? The list of items may increase later. How should I add the items now so that additional items can be added easily?

When I select an item in the combo box and click ok, I need to pop up another window that displays some details. How do I check which item I had selected and display the correct information?

Thanks!
0
Comment
Question by:wmlim060298
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
Voodooman earned 60 total points
ID: 2639483
Use the Add Item method to add to the list.

Combo.addItem "Voodooman" ' a string value

You can do this any time.

To check the value use the textproperty of the combo

Dim mystring as string

mystring=Combo.text

You can also use the Change Event of the combo box to do things.  When the value changes you can pop up a box or whatever.

Beware the change event doesnt always work for some reason - its a Bill Gates bug!!

Voodooman!
0
 
LVL 1

Expert Comment

by:PatrickVD
ID: 2639528
Hi,

Populating comboboxes is a quite simple operation... you just use the AddItem method of the combobox.

Combo1.AddItem "This is the string that appears in the box"

This code just appends an item to the combobox... It doesn't matter if you want to add new items later, you can simply add them in your code ... There isn't a restriction on this.

If you want to know which items was selected in the combobox, you can retrieve the index of that item in the combo's list with the ListIndex property. Beware, if no items are selected in the combobox, it will have the value -1.

As you probably know, the combobox has the List property which contains all the string items being displayed. But, it also contains an ItemData list, which is actually a list in which you can store any 'Long' value. Conceptually, you could say that for each item in the combobox, you can store a 'String' and a 'Long' value.
I very ofter use this Itemdata to store the primary key of the records that contain the details of the displayed items... Then I can retrieve the information later...

I'll now try to make everything clear in view of what you would like to do...

'Add Items to combo
Private Sub AddComboItem(Combobx As Control, ItemString As String, ItemLong As Long)
  'Create the new Item
  Combobx.AddItem ItemString
  'Update this new Item's Long value
  Combobx.ItemData(Combobx.NewIndex) = ItemLong

End Sub

'Now, To display the selected Item details check listindex (assuming this will happen when the user clicks a command button, and that the concerned combobox is named Combo1)

Private Sub Command1_Click()
  Dim lngID as Long

  If Combo1.ListIndex = -1 Then
     MsgBox "Please Select an Item!!"
  Else
     'Retrieve the ID from Itemdata
     lngID = Combo1.ItemData(Combo1.ListIndex)
     'Do data access to retrieve data and display it.
  End If

End Sub


Hope this helps...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question