How to add DB fields to list and textboxes..
Hi
I have to add data of a db ( db.mdb ) to a combo dropdown list ( cmbdrop ).. The table is "order" in db.mdb and field is "id"..
So when the prog is run the list is populated with ID field.. Now when i click on a particular list item.. the corresponding values of that row of table have to show in some txtboxes.. for eg if a particular data field "buy" and "sell" are associated with the field "ID " their value should show on txtbuy.text and txtsell.text automatically when that ID is chosen..
How can i code this???
Re: How to add DB fields to list and textboxes..
SQL-String
Something like:
VB Code:
Private Sub Combo1_Click()
Set rs = New Recordset
rs.Open "SELECT * FROM TABLE WHERE ROW = '" & Combo1.Text & "'", cn, adOpenForwardOnly, adLockReadOnly
If Not rs.EOF And Not rs.BOF Then Text1.Text = rs.Fields("Whatever").Value
rs.Close
End Sub
Re: How to add DB fields to list and textboxes..
There is no point in bringing back every field in your table unless you are going to use every field in your table (and even then, I would list each an every field name rather than using *)
Take what Radjesh Klauke posted, but list the fields in your SELECT and then populate your textboxes using the data from the resulting recordset as Radjesh Klauke demonstrated.
Re: How to add DB fields to list and textboxes..
Re: How to add DB fields to list and textboxes..
Since your using data bound controls, the answer is in the other thread you made.
Re: How to add DB fields to list and textboxes..
Hi
I have managed to populate the list of items in my combo box...
But now the field "item_name" which is populating my combo list also has a msp and a shipping field corresponding to it..
What i want to do is that when a particular Item is selected in the combolist.. the corresponding msp and shipping value should get stored in txtmsp.text and txtship.text which i can display and use later..
please advice on code
Re: How to add DB fields to list and textboxes..
Let me explain more.. The image attached is the simple form ive created
http://img187.imageshack.us/img187/1738/addorderwm6.gif
the DB is : db.mbd
table : to save order : order_details
items detials : item_info
fields in item_info : item_name, msp, shipping
Now I have populated the list by the following code
Code:
Private Sub Form_Load()
' The below is to save order
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(App.Path & "\db.mdb")
Set rs = db.OpenRecordset("order_details", dbOpenTable)
'The below is to get the item detials form another field...
Set ws1 = DBEngine.Workspaces(0)
Set db1 = ws1.OpenDatabase(App.Path & "\db.mdb")
Set rs1 = db1.OpenRecordset("item_info", dbOpenTable)
Do Until rs1.EOF
cmbitem.AddItem rs1!item_name
rs1.MoveNext
Loop
End Sub
Now what i want to do is that when a person click on a particualr item from the list ( cmbitem ).. the MSP and Shipping txt boxes should get populated by the corresponding MSP and shipping from item_info table which is next to the item name..... HOW TO CODE THIS???
and then when a person fills in everything.. and clicks on add order it gets saved in order_detials Table
thanks all..