RowsAffected Property Example

This example illustrates use of the RowsAffected property to determine the number of rows changed by an ambiguous update statement. In this case we do not know how many authors live in Salt Lake City, but once the update takes place, we can determine how many rows were updated by checking the RowsAffected property of the rdoQuery object.

Option Explicit
Dim SQL As String
Dim cn as rdoConnection
Dim qd as rdoQuery

Private Sub Form_Load()
Set cn = rdoEnvironments(0).OpenConnection( _
  dsname:="WorkDB", _
  Prompt:=rdDriverNoPrompt, _
  Connect:="uid=;pwd=;database=pubs")
  
SQL = "Update Authors Set Zip = ?" _
  & " Where City = ?"
Set qd = cn.CreateQuery("FixZip", SQL)
End Sub

Private Sub UpdateButton_Click()
qd(0) = NewZip      ' From a TextBox 
qd(1) = CityToFind   ' From a TextBox
ps.Execute
NumberChanged = qd.RowsAffected
End Sub