timhans
Programmer
- Jun 24, 2009
- 75
Hello, have a form with navigation button's, user's want to delete records the code below work well, but want to give the chance to back out, trying msgbox "xyz",vbOKCancel but after canceling deletes anyway. Any insight is apriciated. Thanks
Private Sub CmdDelete_Click()
On Error GoTo cnnError
If vbOKCancel = True Then GoTo AAA 'Here
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
Dim rsDelete As New ADODB.Recordset
rsDelete.ActiveConnection = cnn
MsgBox "Continue", vbOKCancel 'Here
rsDelete.Open "SELECT * FROM Equipment WHERE DemoID = '" & Me.txtbox1.Value & "'", , adOpenDynamic, adLockOptimistic, adCmdText
If rsDelete.EOF = False Then
With rsDelete
.Delete
.Update
.Close
End With
End If
MsgBox "Record Deleted", vbInformation
AAA: 'Here
Set rsDelete = Nothing
Set cnn = Nothing
Exit Sub
cnnError:
MsgBox "There was an Error Connecting to the DataBase." & Chr(13) _
& Err.Number & ", " & Err.Description
Private Sub CmdDelete_Click()
On Error GoTo cnnError
If vbOKCancel = True Then GoTo AAA 'Here
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
Dim rsDelete As New ADODB.Recordset
rsDelete.ActiveConnection = cnn
MsgBox "Continue", vbOKCancel 'Here
rsDelete.Open "SELECT * FROM Equipment WHERE DemoID = '" & Me.txtbox1.Value & "'", , adOpenDynamic, adLockOptimistic, adCmdText
If rsDelete.EOF = False Then
With rsDelete
.Delete
.Update
.Close
End With
End If
MsgBox "Record Deleted", vbInformation
AAA: 'Here
Set rsDelete = Nothing
Set cnn = Nothing
Exit Sub
cnnError:
MsgBox "There was an Error Connecting to the DataBase." & Chr(13) _
& Err.Number & ", " & Err.Description