Results 1 to 2 of 2
  1. #1
    Lounger
    Join Date
    Dec 2003
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    update condition (Access 2000)

    I have a good function that updates the field EndPrice with the field grossprice I need however to improve the function and update only those products where
    the size is less than 6 or < 6. .I have a field called size in the table products.I understand i have to insert also size in the select clause, but how can i formulate the condition ?
    All the products with a size greater than 6 should have a 0 Value.

    Below is my working function that needs to be changed with the aboce condition.


    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT grossprice, endprice FROM products")
    rs.MoveFirst
    Do
    rs.Edit
    rs.Fields("endprice") = EndPrice(rs.Fields("grossprice"))
    rs.Update
    rs.MoveNext
    Loop While Not rs.EOF

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: update condition (Access 2000)

    You can do it like this:

    Set rs = CurrentDb.OpenRecordset("SELECT grossprice, endprice FROM products WHERE size < 6")

    if you want to update only records for which size < 6, as you state first. If, as you state later, you want to set endprice to 0 for records not satisying the condition, it is different:

    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT grossprice, endprice, size FROM products")
    rs.MoveFirst
    Do
    rs.Edit
    If rs.Fields("size") < 6 Then
    rs.Fields("endprice") = EndPrice(rs.Fields("grossprice"))
    Else
    rs.Fields("endprice") = 0
    End If
    rs.Update
    rs.MoveNext
    Loop While Not rs.EOF

Posting Permissions

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