Link to home
Start Free TrialLog in
Avatar of Peanuthead
Peanuthead

asked on

Help w/combo boxes

I am designing a database type program that the user will be able to add a name to a combobox, then when they want to acess the data under that name, they click on the name in the combobox.  I know this is quite simple...BUT...i need to know how to get the data from the combobox without using about 500 if..then loops(up to 500 items can be stored).  So instead of typing- if combo1.index = 1 then...
                      if combo1.index = 2 then...
etc.
how would i have the program like KNOW what the currently selected index value is.  I have defined a type that has the item's name, price, date purchased, and additional info.  These are all filled into different text boxes and then when u click a button, it clears these boxes and adds the name of the item to the combobox.  thats basically how the program works, just to clarify it for ya.  thx
Avatar of dudemann
dudemann

If I understand your question correctly, you want to get the index and value of an item selected in a combobox.  I printed these in the immediate window.  

' This one prints the value of the item selected in the combobox
?frmAdhocReports.cboYear.List(frmAdhocReports.cboYear.ListIndex)
1999

' This one prints the value of index for the item selected in the combobox.
?frmAdhocReports.cboYear.ListIndex
 3

Hopefully this is what you are looking for!
This is done differently in say Access than in Visual Basic.  If you are using standard Visual Basic then the previous two comments are on track to get you where you are going so try working with those.  

If you are in Access there is a whole other set of information you will want as well.  One thing I will throw out again is that you should always consider not binding your controls directly to your data tables unless you are certain that will provide some improvement to your methods or processing.  Typically programs like Access will warn you when for instance you've populated a bound field with an invalid value.  VB will blow up with an error instead - teaching us that ON ERROR handling in VB has to be a constant consideration.  I've almost always hidden my bound controls off screen and used unbound controls to interface with the user as display and get inputs.  This is not the Access area but if you are indeed working in Access by some chance let me know I'll rant onward.
Avatar of Peanuthead

ASKER

I dont think that u quite understood what im asking...
What i need to know is:
How do i make a combobox that the user can add names to, and these names can then be reselected and the information can be shown about them.  The trouble im having is that i dont want to have 500 if..then statements for each index value of the combobox when they select a name.  So what i need is a way for the program to recognize the current index value being shown.  Ask about anything that needs clarification.
what ever item in the combo box is selected will be stored as  cbobox.text
I need to use indexes because each name causes other info to appear upon clicking it.
Avatar of Éric Moreau
Is it possible to keep a collection or an array that will contains extra information that your combo won't. Keeping the same index will easier your work for retreiving from the other structure!
ASKER CERTIFIED SOLUTION
Avatar of VBKid
VBKid

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could use a command button or an item in your combobox entitled "Add Name".  Whenever you fire the event, you could use an InputBox that gets the name, then add the name to the database, get the cboName.count, additem the new name, and the cboName.count is prob the index of that new name.  Then you could do a cboName.ListIndex = cboName.count.  You could also, after saving the new record, do a select on that table to re populate your cboBox.