The Command Execute Method

You can also execute an action query by calling the Execute method against a Command object. cmd.Execute RecordsAffected, Parameters, Options

Simply set the command object's CommandText, CommandType, and ActiveConnection properties; then call the Execute method. The Parameters property can be populated by a variant array of parameter values passed with an SQL statement. The Options property defines the provider how to evaluate the CommandText property (refer to previous table).

Dim cn As New ADODB.Connection

Dim cmd As New ADODB.Command

Dim strSQL As String

Dim RA As Long

'Open the connection cn.Open CurrentProject.Connection

'Setup the SQL statement strSQL = "UPDATE Suppliers SET Region = 'None'"

With cmd

.CommandText = strSQL .CommandType = adCmdUnknown .ActiveConnection = cn .Execute RA End With

Debug.Print RA & " records were updated." cn.Close

Set cmd = Nothing Set cn = Nothing

0 0

Post a comment