Hi All,
I have a form. The source of the form is a query which prompts the user to enter a date. When the date is entered, all applicable records are returned. Simple stuff. So, I have a "delete" command button on my form. It works fine. The problem is, if say, the user wanted to delete a record and it was the only record showing, the record gets deleted and then the form just goes blank. What I would like to do, is add some code to the existing command (below) that brings up a YN box and says something like "You have deleted the last record for this date. Return to home screen?" and when the user clicks "yes", the program returns to the user interface/switchboard. If there are more records to show, the delete function would act normally and just show the next record.
Is my idea possible? Can anyone help me out? Your help is greatly appreciated. The command code is below:
Private Sub cmdDeleteRecord_Click()
On Error GoTo Err_cmdDeleteRecord_Click
Dim mbxresponse As VbMsgBoxResult
mbxresponse = MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo)
If mbxresponse = vbYes Then
Call DoCmd.SetWarnings(False)
Call DoCmd.RunCommand(acCmdDeleteRecord)
Call DoCmd.SetWarnings(True)
Else
Call MsgBox("The record was not deleted")
End If
Exit_cmdDeleteRecord_Click:
Call DoCmd.SetWarnings(True)
Exit Sub
Err_cmdDeleteRecord_Click:
Call MsgBox("The record was not deleted" & vbCrLf & vbCrLf & _
"Description: " & Err.Description & vbCrLf & _
"Error Number: " & Err.Number, , _
"Error Deleting Record")
Resume Exit_cmdDeleteRecord_Click
End Sub
I have a form. The source of the form is a query which prompts the user to enter a date. When the date is entered, all applicable records are returned. Simple stuff. So, I have a "delete" command button on my form. It works fine. The problem is, if say, the user wanted to delete a record and it was the only record showing, the record gets deleted and then the form just goes blank. What I would like to do, is add some code to the existing command (below) that brings up a YN box and says something like "You have deleted the last record for this date. Return to home screen?" and when the user clicks "yes", the program returns to the user interface/switchboard. If there are more records to show, the delete function would act normally and just show the next record.
Is my idea possible? Can anyone help me out? Your help is greatly appreciated. The command code is below:
Private Sub cmdDeleteRecord_Click()
On Error GoTo Err_cmdDeleteRecord_Click
Dim mbxresponse As VbMsgBoxResult
mbxresponse = MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo)
If mbxresponse = vbYes Then
Call DoCmd.SetWarnings(False)
Call DoCmd.RunCommand(acCmdDeleteRecord)
Call DoCmd.SetWarnings(True)
Else
Call MsgBox("The record was not deleted")
End If
Exit_cmdDeleteRecord_Click:
Call DoCmd.SetWarnings(True)
Exit Sub
Err_cmdDeleteRecord_Click:
Call MsgBox("The record was not deleted" & vbCrLf & vbCrLf & _
"Description: " & Err.Description & vbCrLf & _
"Error Number: " & Err.Number, , _
"Error Deleting Record")
Resume Exit_cmdDeleteRecord_Click
End Sub