in my form, there is a combobox(of product) and textbox(of price), once the combobox select a value, it will appear some value in textbox that related to the content of the same row.
for example in table1
product: orange juice
when the user select the product (biscuit) from combobox, automatically the textbox will apppear "20"(it work well), but now my problem is when i run this program(before adding new record), when press "next", the value of name will move next record by record. but let said i add record2 again. after saving, it will move to the first record. but the value of price is not 20, is 3,(the ID and product will move next or previous record by record, it work well)what's going on?
i link the ID, product , price to ado_stock. so that it will save whatever value into table1.
here are my code:
Private Sub cbo_product_Click()
Dim price As String
price= "SELECT Price FROM table1 WHERE Product LIKE '" &cbo_product & "'"
ado_price_sql.CommandType = adCmdText
ado_price_sql.RecordSource = price
Set txtPrice.DataSource = ado_price_sql
'get the product from table_product
Private Sub cbo_product_DropDown()
cbo_product.Clear 'Clear the Combo box
If ado_product.Recordset.RecordCount > 0 Then
Do While Not ado_product.Recordset.EOF
Private Sub cmd_saveP_Click()
ado_stock.Recordset.Fields("Price").Value = txtPrice.Text
ado_stock.Recordset.Save 'Save the record
Call MsgBox("Your changes have been sucessfully made!",
When you save the record, you say it moves to the first record - what in your code is causing the recordset to move to the first record ? In this example, are there only the 2 records ? Are you using the ado data control ? Is the price of the 2nd record really in record 1 or are the fields just out of sync ?
yes, i 'm using ado control(.save).in my data base it is not only 2 record. under access, when u check back to the table which is table_stock, it is with different price, is not what that the price of the second record will replace the price of first record.but in form, when u run it before saving new record, "next" button u press, it works, the price will move to next record, but after u save it, u play "next", the price will be the same no matter which record u are state.
yes, i ' m using ado (.save ) to save the record. check backto the database, the price is different, the second's record price will not replace the price of first record. but under visual basic, before save a new record contain a new price, pressing "next", it work well, it will move to the next record.but after saving a new record, press "next" button again, every record will state with the same price, but the value of combo box will move next, the problem is only the text box.
Let me see if I understand the problem: You move next using the ado data control and everything is ok. But you click on your save button and the text box with a price stays the same for all records. But the database reflects the correct price, so basically you are losing the link between your text box and data control - the data in the database is not changing to this constant price that you see on your form. How are you creating a new record ? Could you post the mdb/vb project ?