Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO Return number of recs altered by SQL command

Status
Not open for further replies.

shallman

Technical User
Jul 21, 2003
22
0
0
US
How do I get the number of records altered by a SQL command returned to my program using ADO. The code I am using is below and works great, but I want to be able to pass on to the user the number of records the SQL command actually affected.

Thanks!
-------------------------
Sub PurgeFundAmountRecs()
'This sub will remove all FundAmount records that are older than 4 years from
'from the FundAmounts table.

On Error GoTo PurgeFundAmts_Error
Dim SqlStr As String
Dim DeleteYear As String
Dim conn As ADODB.Connection
Dim Cmd As ADODB.Command
Dim adoerr As ADODB.Error

DeleteYear = Year(Date) - 5
Set conn = CurrentProject.Connection
Set Cmd = New ADODB.Command
Set Cmd.ActiveConnection = conn
SqlStr = &quot;DELETE FROM [FundAmounts] WHERE FundAmounts].YearID <= &quot; & DeleteYear
Cmd.CommandText = SqlStr
Cmd.CommandType = adCmdText
Cmd.Execute RecordsAffected:=recs, Options:=adExecuteNoRecords
Set Cmd = Nothing

MsgBox (&quot;FundAmounts table has been successfully purged&quot;)
Exit Sub

PurgeFundAmts_Error:
With conn
If .Errors.Count > 0 Then
For Each adoerr In conn.Errors
MsgBox (&quot;The Error is&quot; & adoerr.Number & &quot; &quot; & adoerr.Description)
Next
End If
End With

End Sub
 
Please disregard, I found it right under my nose. The &quot;recs&quot; variable contains the value of records affected by the SQL command.
Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top