Executing an Update Query : SQL Update « Access « VBA / Excel / Access / Word






Executing an Update Query

 
Sub Execute_UpdateQuery()
   Dim conn As ADODB.Connection
   Dim NumOfRec As Integer
   Dim strPath As String

   strPath = CurrentProject.Path & "\mydb.mdb"

   Set conn = New ADODB.Connection

   conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath

   conn.Execute "UPDATE Products SET UnitPrice = UnitPrice + 1" & _
      " WHERE CategoryId = 8", NumOfRec, adExecuteNoRecords

   Debug.Print NumOfRec & " records were updated."
   conn.Close
   Set conn = Nothing
End Sub

 








Related examples in the same category

1.Get the updated record count
2.Executing an Update Query using the Command Object
3.Listing All Saved Queries in a Database
4.Deleting a Stored Query