Hi all,
I have a form with a sub form and a delete button residing on the form.
When pressed, the sub form records are deleted, then i am asked if I want to delete 1 record. If I say no, the form record stays put, but the sub form stuff still gets deleted. I know I just have the code in the wrong place and I'm hoping someone can help me out, as I have limited VBA experience.
Here is my code:
I have a form with a sub form and a delete button residing on the form.
When pressed, the sub form records are deleted, then i am asked if I want to delete 1 record. If I say no, the form record stays put, but the sub form stuff still gets deleted. I know I just have the code in the wrong place and I'm hoping someone can help me out, as I have limited VBA experience.
Here is my code:
Code:
Private Sub cmdCancel_Click()
Dim intID As Integer
If Not IsNull(Me.ReservationID) Then
intID = Me.ReservationID
Else
Exit Sub
End If
CurrentDb.Execute "DELETE tblReservation_details.* " & _
"FROM tblReservation_details " & _
"WHERE reservationID=" & intID
Me.SubfrmReservation_Details.Requery
On Error GoTo cmdcancel_Click_Err
On Error Resume Next
DoCmd.GoToControl Screen.PreviousControl.Name
Err.Clear
If (Not Form.NewRecord) Then
DoCmd.RunCommand acCmdDeleteRecord
End If
If (Form.NewRecord And Not Form.Dirty) Then
Beep
End If
If (Form.NewRecord And Form.Dirty) Then
DoCmd.RunCommand acCmdUndo
End If
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If
cmdcancel_Click_Exit:
Exit Sub
cmdcancel_Click_Err:
MsgBox Error$
Resume cmdcancel_Click_Exit
End Sub