Edit Method Example

This example finds the first record in a recordset matching the search criteria and opens it for editing.  Then it changes the value in the Title field and saves the change using the Update method.

Dim Criteria As String, NewTitle As String
Criteria = "Title = 'My Right Hand'"           ' Create the criteria.
NewTitle = "My Right Foot"                     ' Create a new title.
Data1.Recordset.FindFirst Criteria             ' Make record current.
Do While Not Data1.Recordset.NoMatch
  If Not Data1.Recordset.NoMatch Then
    Data1.Recordset.Edit                       ' Open record.
    Data1.Recordset.Fields("Title") = NewTitle ' Enter new title.
    Data1.Recordset.Update                     ' Save changes.
  End If
  Data1.Recordset.FindNext Criteria

The following example achieves the same effect:

Dim SQLQuery As String, NewTitle As String
' Create the Criteria string
SQLQuery = "UPDATE Titles SET Title = 'My Right Foot'"
SQLQuery = SQLQuery & " WHERE Title = 'My Right Hand'"
Data1.Database.Execute SQLQuery               ' Execute the query.