I set up a delete button on a form, that has five linked subforms. Here is the code I used:
I didn't use the cascading delete feature in the relationships set-up because then it would be too easy for someone to delete things. I set it up so a password has to be entered in order to delete anything, however, I get an error message that says "Too few parameters. Expected: 1". I have checked and re-checked, and all field and table names are spelled correctly.
Can anyone shed some light on this? Any ides would be appreciated.
Wayne
Code:
Private Sub btnContinueDelete_Click()
On Error GoTo Err_btnContinueDelete_Click
Dim strPathPassword As String
Dim db As DAO.Database
Dim strQryDetails As String
Dim strQryNotes As String
Dim strQryDocs As String
Dim strQryPix As String
Dim strQryAssign As String
'Create the string for the Password Check
strPathPassword = DLookup("[DeletePassword]", "tblSysConfig", "[CompanyName] = '" & [Forms]![frmOrders]![CompanyName] & "'")
'Create the strings for deleting the various child records
strQryDetails = "DELETE * FROM [tblOrderDetails] WHERE [OrderNumber] =" & [Forms]![frmOrders]![OrderNumber]
strQryNotes = "DELETE * FROM [tblOrdersNotes] WHERE [OrderNumber] =" & [Forms]![frmOrders]![OrderNumber]
strQryDocs = "DELETE * FROM [tblDocuments] WHERE [OrderNumber] =" & [Forms]![frmOrders]![OrderNumber]
strQryPix = "DELETE * FROM [tblJobPix] WHERE [OrderNumber] =" & [Forms]![frmOrders]![OrderNumber]
strQryAssign = "DELETE * FROM [tblOrdersAssign] WHERE [OrderNumber] =" & [Forms]![frmOrders]![OrderNumber]
If Me.txtPasswordDelete = strPathPassword Then
Set db = CurrentDb
'Delete the child records first
CurrentDb.Execute strQryDetails, dbFailOnError
CurrentDb.Execute strQryNotes, dbFailOnError
CurrentDb.Execute strQryDocs, dbFailOnError
CurrentDb.Execute strQryPix, dbFailOnError
CurrentDb.Execute strQryAssign, dbFailOnError
'Delete the parent record
DoCmd.Close acForm, "frmPasswordDelete", acSaveNo
DoCmd.RunCommand acCmdDeleteRecord
MsgBox "This record, and all related records have been deleted.", vbInformation, "Success!"
Else
MsgBox "The password you entered is incorrect.", vbInformation, "Try Again"
Exit Sub
End If
Set db = Nothing
Exit_btnContinueDelete_Click:
Exit Sub
Err_btnContinueDelete_Click:
MsgBox Err.Description, vbInformation, "Error!"
Resume Exit_btnContinueDelete_Click
End Sub
I didn't use the cascading delete feature in the relationships set-up because then it would be too easy for someone to delete things. I set it up so a password has to be entered in order to delete anything, however, I get an error message that says "Too few parameters. Expected: 1". I have checked and re-checked, and all field and table names are spelled correctly.
Can anyone shed some light on this? Any ides would be appreciated.
Wayne