Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2002
    Location
    malaysia
    Posts
    9

    Unanswered: textbox value cannot move to next

    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
    *record1:
    ID:3000
    product:biscuit
    price:20

    *record2:
    ID:3001
    product: orange juice
    price:3

    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
    ado_price_sql.Refresh
    End Sub
    __________________________________________
    'get the product from table_product
    Private Sub cbo_product_DropDown()
    cbo_product.Refresh
    cbo_product.Clear 'Clear the Combo box
    If ado_product.Recordset.RecordCount > 0 Then
    ado_product.Recordset.MoveFirst
    Do While Not ado_product.Recordset.EOF
    cbo_product.AddItem ado_product.Recordset.Fields("Product").Value
    ado_product.Recordset.MoveNext
    Loop
    End If
    cbo_product.Refresh
    End Sub
    ____________________________________________

    Private Sub cmd_saveP_Click()
    ado_stock.Recordset.Fields("Product").Value=cbo_pr oduct.Text
    ado_stock.Recordset.Fields("Price").Value = txtPrice.Text
    ado_stock.Recordset.Save 'Save the record
    Call MsgBox("Your changes have been sucessfully made!",
    vbInformation, "Save")
    End Sub

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    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 ?

  3. #3
    Join Date
    Mar 2002
    Location
    malaysia
    Posts
    9

    HELPPPPP!!!!!!!

    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.

  4. #4
    Join Date
    Mar 2002
    Location
    malaysia
    Posts
    9

    HELP!!!!!!

    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.

  5. #5
    Join Date
    Feb 2002
    Posts
    2,232
    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 ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •