Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Data to a combo box from a table

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I am adding data to a combo box from a SQL table. my question is, why does my code only fire off the Got Focus event? it wont work for the Click Event. also once the combo box has the fields from the table is there anyway to stop it from duplicating the list?? whats happening is if I choose an item from the combo box the first time is ok. But if i go back to the combo box to change the item it will add the items from the table again. so now there are double the items in the combo box.

any help would be appreciated
thanks
 
It would help if you post your code. The list duplication is solved by calling the Combo Boxes Clear procedure before you fill it again. Post your code and we can take a look at the click event problem. Anything is possible, the problem is I only have one lifetime.
[cheers]
 
I have recently been showing my VB evening class students to do what sounds very simiilar to what you are trying to do. But why do you want to load the combo box in response to a combo box event? My suggstion is to load it from the load event of the form. Alternatively, put a button on the form and put the code into that. You could start off with a clear command, so every time you click the button, the combo box is reloaded from the database, once only.
 
OK. I did it on the form load event..worked fine but I need the combo box to be blank once the form opens. And also when the user adds the record the combobox should then be cleared. if I do cboCombo.Clear it will unload the data from the table. I added a field in the table pressing the space bar once so the first thing in the combo box looks blank. but I cannot use that since I have conditions that force the user to make a choice in both combo boxes. So if the user leaves the combo box blank it will not let him add the record. since there would be a record that would appear blank the conditions would then be met letting the user add the record.
 
When you say you want to clear the combo after the record is added, if your combo is either style 1 or style 0, you should be able to use combo1.text = ""

If you have put your code into the change event, you might want to consider moving it to the click event
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top