Question : Deleting multiple records using checkboxes as the record selector

I have a form with a subform.  The subform is set a as a  continuous form.  I'd like to have a check boxes that acts as a record selector within the subform and one delete button in the header.  I want to allow the user to select multiple records using the check box and delete them.

The checkbox is bound to a field "isSelected"  If a record cannot be deleted because there are child records associated then a message box to show which "checked" record(s) has child records that first need to be deleted.


thnx

Answer : Deleting multiple records using checkboxes as the record selector

Here is a SQL string that will do what you want; you run it from a command button in the header, substituting your table name (you should Requery the subform afterwards):
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Private Sub cmdDeleteSelectedRecords_Click()

   Dim strSQL As String
   Dim strTable As String
   
   strTable = "tblContacts"
   strSQL = "DELETE " & strTable & ".*, IsSelected " _
      & "From " & strTable & " WHERE IsSelected=True;"
   Debug.Print "SQL string: " & strSQL
   DoCmd.RunSQL strSQL
   
End Sub
Random Solutions  
 
programming4us programming4us