Private Sub cmdDelete_Click()
Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
Dim sql As String
Dim rsDelete As New ADODB.Recordset
'Build dynamic SQL statement based on
'record selected by user.
sql = "select * from Products where Main_ID = " & _
Val(Me.txtRecordID.Value)
'Assign updatable cursor and lock type properties.
rsDelete.CursorType = adOpenDynamic
rsDelete.LockType = adLockOptimistic
'Open the Recordset object.
rsDelete.Open sql, cnn, , , adCmdText
'Don't try to delete the record, if the
'recordset did not find a row.
If rsDelete.EOF = False Then
'Update the record based on input from the user.
With rsDelete
.Delete
.Update
.Close
End With
'Close the form-level Recordset object and refresh
'it to include the newly updated row.
rsDelete.Close
Set rsDelete = Nothing
End If
End Sub
|