|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Combo box from a data base
Is there a way to get multible combo boxs to read from a database
or something of the such. I have about 5 combo boxs on the same form. I wanna be able to add something to the data base or whatever works with combo boxs. So I can enter something in the database once instead of 5 different times. |
|
#2
|
||||
|
||||
|
give me a little more info here.. what exactly would you like to accomplish?
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#3
|
|||
|
|||
|
OK I was planing on trying to do this step by step but I can tell you what I am really wanting. I am trying to make somethign for my dad to figure up prices on material. I have made a form and it kinda looks like this. Desrciption/Unit Price/Amount of Units/Total all. I am trying to make it where the description is a cmbobox. So when he selects from it that it will put that in the description area and the unit price in the unit price area. You can see an example here I am wanting all the combo boxs to call from the same place so I don't have to put it in like 50 times.
|
|
#4
|
||||
|
||||
|
oh... gotcha. Is it necessary for him to be able to add text into the combo boxes? If not, then I would use a listbox, or make the combo so that it is not updateable... but now for your question. After you open your connection and your recordset (I'm guessing at the beginning of your app), load the combo with a loop that steps through the recordset and pull out your defining field. Then, in the click event of your combo box, use the fact that both your combo box and your recordset are zero-based arrays. To do this, do a move in your recordset based on the index of your combo. So
Code:
Private Sub cboYourCombo_Click()
rsYourRecordset(cboYourCombo.Listindex,0)
'I would use text boxes to hold any values not selectable or
' self defining.
txtBox1.text=rsYourRecordset(0)
txtBox2.text=rsYourRecordset(1)
txtBox3.text=rsYourRecordset(2)
End Sub
|
|
#5
|
|||
|
|||
|
Is there a way to give it a value. So that once the item that is in the combo box is selected the items unit price will be put in auto maticly.
Also, I would like to set it where I can use a add feature, because prices change sometimes. Also he may have new things come about. I create a small form I hope can be added it has a layout kinda like the one shown in the above link but with only one combo box for adding the description and unit price. |
|
#6
|
|||
|
|||
|
If you would like to look at my code I can zip and email it. So you can tell more about what I am doing. Also I am very new so I am sure the code could be simplefied alot. Just let me know.
|
|
#7
|
||||
|
||||
|
well, using the code I gave you before, you should be able to update the form's text boxes automatically whenever the new combo box item is selected. Also, I would use a separate form to update your database. It makes more sense logically, although you could simply use a module-level boolean, say (mblnDirty) and set it to True whenever one of the text_changed events occurs for the text boxes. You can also use another module-level boolean, maybe called mblnEditMode, to designate whether the user has elected to add a new item to the database. Here's how I would do it...
have a form with your combo, text boxes, and buttons labeled as "Add New", "Edit Existing", "Update Database", and whatever other functionality you want. When you click the "Add New" button, clear the text boxes and the combo text field, and enable the text boxes (set a boolean, maybe mblnAddMode=True) and disallow all buttons except "Update Database". Allow the user to input new data and do validation, finishing the new record by clicking "Update Database", then reintialize your list and refresh your screen. Then, when you click "Edit Existing", turn on another bln (maybe mblnEditMode), unlock the text boxes and allow the user to change the fields. Validate the data when the user clicks the "Update Database" button, post the data back to the database, and reintialize the list. I don't know if all that made sense.. zip your code if you want to.. i'll be happy to look at it. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Combo box from a data base |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|