It's been 8 years since I've taken a Visual Basic class and I'm a bit rusty. Just starting to use VBA for a db I'm designing.
I have a multiple items form with a tabular layout. When this form is loaded, it filters in only at a few select records.
At the bottom, I added a "Delete Button" which allows the user delete one of the above current records with:
DoCmd.SetWarnings False 'Removes warning box on deletion
DoCmd.RunCommand acCmdDeleteRecord 'Deletes current record
DoCmd.SetWarnings True 'Reinstates warnings before deleting
However, if there is no record to be deleted (either they have already all been deleted or there is no records to begin with) and the user hits the Delete Button, the program flips out. How can I have it catch that, so if there are no records to be deleted a MsgBox says "There are no records to be deleted" and the delete does not run?
I have a multiple items form with a tabular layout. When this form is loaded, it filters in only at a few select records.
At the bottom, I added a "Delete Button" which allows the user delete one of the above current records with:
DoCmd.SetWarnings False 'Removes warning box on deletion
DoCmd.RunCommand acCmdDeleteRecord 'Deletes current record
DoCmd.SetWarnings True 'Reinstates warnings before deleting
However, if there is no record to be deleted (either they have already all been deleted or there is no records to begin with) and the user hits the Delete Button, the program flips out. How can I have it catch that, so if there are no records to be deleted a MsgBox says "There are no records to be deleted" and the delete does not run?