Microsoft Access 2010 Bible

(Rick Simeone) #1

Part II: Programming Microsoft Access


520


strSQL holds a SQL statement for locating and deleting records in tblSalesPayments with an
invoice number that matches the invoice number on frmSales. strSQL is passed as a parameter
to the Execute method of the current project’s (CurrentProject) connection. You can pass
either the name of a query or a SQL statement as a parameter to the Execute method. The
Execute method simply runs the specified query or SQL statement.

FIGURE 13.21

Using ADO code to delete multiple records


Note
If the query or SQL statement contains a WHERE clause and the Execute method does not find any records
that meet the WHERE condition, no error occurs. If the query or SQL statement contains invalid syntax or an
invalid field or table name, however, the Execute method fails and an error is raised.


The same process is used to delete records in tblSalesLineItems.

After the tblSalesLineItems records are deleted, the tblSales record can then be deleted.
The following listing shows a slightly different way to write the cmdDelete_Click procedure.

Private Sub cmdDelete_Click()
Dim intAnswer As Integer
Dim strSQL As String
If Me.NewRecord Then
Me.Undo
Exit Sub
End If
Free download pdf