Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2012
    Posts
    29

    Unanswered: Append data from a form to a table

    I am new to access. I have also read most of the post on "append data" this is my problem.
    I need to append 2 types of data product and price
    I have read previous post and it has helped greatly.
    I am using this code
    Private Sub product_Click()
    Dim db As Database
    Dim rs As DAO.Recordset
    Set db = CurrentDb()
    Set rs = db.OpenRecordset("SELECT * FROM CustomerOrder WHERE(Product = """ & Me.Product & """)")
    If rs.EOF Then
    With rs
    .AddNew
    .Fields("Product") = Me.Product.Text
    .Update
    .Close
    I can only add the product but i also need to add the price of the item

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Why don't you use:
    Code:
    With rs
    .AddNew
    .Fields("Product") = Me.Product.Value
    .Fields("Price") = Me.Price.Value
    .Update
    .Close
    Note: Never use the Text property of a TextBox control to retrieve its value.
    Have a nice day!

  3. #3
    Join Date
    Aug 2012
    Posts
    29

    thanks

    Thanks going to try

  4. #4
    Join Date
    Aug 2012
    Posts
    29
    It works fine the only problem I need to Duplicate items, when more than one customer orders.

    Thanks

  5. #5
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Code:
    With rs
        For i = 1 to < count of customer orders>
            .AddNew
            .Fields("Product") = Me.Product.Value
            .Fields("Price") = Me.Price.Value
            .Update
        Next i
        .Close
    End With
    Have a nice day!

  6. #6
    Join Date
    Aug 2012
    Posts
    29
    Thanks for the help
    I am getting a compilation error "For i = 1 to < count of customer orders>"
    This part of the code turns red

  7. #7
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    < count of customer orders> must of course be replaced by the number of times you want to insert a new row into the table.
    Have a nice day!

  8. #8
    Join Date
    Aug 2012
    Posts
    29
    Thanks It works but not exactly as i would like . It adds all at once but I would like to add one at a time

  9. #9
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You get what you ask for:
    Quote Originally Posted by kim40 View Post
    It works fine the only problem I need to Duplicate items, when more than one customer orders.
    If there are other conditions that must be included into the function, please explain them clearly:
    Quote Originally Posted by kim40 View Post
    Thanks It works but not exactly as i would like . It adds all at once but I would like to add one at a time
    Have a nice day!

  10. #10
    Join Date
    Aug 2012
    Posts
    29
    thanks for your help

  11. #11
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!

    However, you did not explain precisely what you're trying to achieve. Please don't hesitate to ask.
    Have a nice day!

  12. #12
    Join Date
    Aug 2012
    Posts
    29
    I did get it to work, I took out the extra parenthasis in the code from the record set

Posting Permissions

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