Results 1 to 6 of 6

Thread: .Update Method

  1. #1

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    .Update Method

    When updating values in a Row of a Recodset, which is the 'correct' option:
    VB Code:
    1. rs.Open sql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    2.  
    3.             With rs
    4.                 .Update "Project_Title", cboProject_Title.Value
    5.                 .Update "Date_Entered", txtDate_Entered.Value
    6.                 .Update "Title", txtTitle.Value
    7.             End With
    8.  
    9.         rs.Update
    10.  
    11.     rs.Close
    Or
    VB Code:
    1. rs.Open sql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    2.  
    3.             With rs
    4.                 .Fields("Project_Title") = cboProject_Title.Value
    5.                 .Fields("Date_Entered") = txtDate_Entered.Value
    6.                 .Fields("Title") = txtTitle.Value
    7.             End With
    8.  
    9.         rs.Update
    10.  
    11.     rs.Close


    Cheers,
    Bruce.

  2. #2
    Hyperactive Member tpfkanep's Avatar
    Join Date
    Jun 2002
    Location
    South Africa
    Posts
    272

    Re: .Update Method

    Originally posted by Bruce Fox
    When updating values in a Row of a Recodset, which is the 'correct' option:
    VB Code:
    1. rs.Open sql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    2.  
    3.             With rs
    4.                 .Update "Project_Title", cboProject_Title.Value
    5.                 .Update "Date_Entered", txtDate_Entered.Value
    6.                 .Update "Title", txtTitle.Value
    7.             End With
    8.  
    9.         rs.Update
    10.  
    11.     rs.Close
    Or
    VB Code:
    1. rs.Open sql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    2.  
    3.             With rs
    4.                 .Fields("Project_Title") = cboProject_Title.Value
    5.                 .Fields("Date_Entered") = txtDate_Entered.Value
    6.                 .Fields("Title") = txtTitle.Value
    7.             End With
    8.  
    9.         rs.Update
    10.  
    11.     rs.Close


    Cheers,
    Bruce.
    I would also like to know.

    I use :
    VB Code:
    1. With rs
    2.     !Project_Title = cboProject_Title.Value
    3.     !Date_Entered = txtDate_Entered.Value
    4.     !Title = txtTitle.Value
    5. End With
    Anything wrong with that?

  3. #3
    Lively Member
    Join Date
    Oct 2002
    Posts
    112
    Bruce I always use your second method as it means only one update which will presumably be faster than the 1st method.

    JFK

  4. #4
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    Originally posted by JFK
    Bruce I always use your second method as it means only one update which will presumably be faster than the 1st method.

    JFK
    Same here, it also is better to have an update that works all the way than half.

    When there is a value which can't be inserted into a certain field then the update won't go through for the whole record.
    If instead there were already two or more fields updated you got a problem.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  5. #5

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Thanks Guys,

    BTW I was using the second method. I just had to get a warm n fuzzy tho


    I guess my question stemed from the syntax for .Update, like:
    rs.Update(Fields, Value) and from that thought the first
    method may (should) be the way to go.



    Like, you would generaly have say:
    VB Code:
    1. rs.Open bla bla bla
    2.     [b]rs.AddNew[/b]
    3.       '
    4.       ' manipulae the RecordSet
    5.       '
    6.   rs.Close
    where the rs Command directly followed the rs.Open statement.


    Anyhoo,
    Cheers.
    Bruce.
    Last edited by Bruce Fox; Feb 21st, 2003 at 07:03 AM.

  6. #6

    Thread Starter
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Originally posted by swatty
    When there is a value which can't be inserted into a certain field then the update won't go through for the whole record.
    If instead there were already two or more fields updated you got a problem.

    Good point swatty!



    Bruce.

Posting Permissions

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



Click Here to Expand Forum to Full Width