Solved Problem with delete Qry (1 Viewer)

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 10:32
Joined
Apr 1, 2019
Messages
708
All, The 'PartyID' passed to the where statement is causing me grief. the value is not being passed, rather the text 'PartyID' is being passed. I suspect its simple syntax issue but I haven't figured it.

Appreciate some help.

Code:
Public Function DeleteRecord(PartyID As Long)
    On Error GoTo Error_Handler
    Dim db                    As DAO.Database
    Dim sSQL                  As String


    Set db = CurrentDb
    MsgBox PartyID
  
    sSQL = "DELETE tblParty.PartyID, tblParty.DateOrigination " & vbCrLf & _
    "FROM tblParty " & vbCrLf & _
    "WHERE (((tblParty.PartyID)=PartyID));"
    
    Debug.Print sSQL
    db.Execute sSQL, dbFailOnError


    If db.RecordsAffected = 0 Then
        MsgBox "No New records were created by the above query?"
    End If
    
Error_Handler_Exit:
    On Error Resume Next
    If Not db Is Nothing Then Set db = Nothing
    Exit Function


Error_Handler:
    MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: cmd_AddRec_Click" & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Function
 

Josef P.

Well-known member
Local time
Today, 22:32
Joined
Feb 2, 2023
Messages
763
Code:
sSQL = "DELETE tblParty.PartyID, tblParty.DateOrigination " & vbCrLf & _
    "FROM tblParty " & vbCrLf & _
    "WHERE (((tblParty.PartyID)=" & PartyID & "));"
                                ^
or
Code:
sSQL = "DELETE FROM tblParty WHERE PartyID=" & PartyID
 

cheekybuddha

AWF VIP
Local time
Today, 21:32
Joined
Jul 21, 2014
Messages
2,188
Remember, a DELETE query deletes the whole record (row) from the table.

You are specifying specific fields. Are you just trying to clear the values from those two fields and leave alone the values in the other fields in the record?

If so, then you would actually need an UPDATE query.

(Unlikely, since you appear to be wanting to delete the PartyID which we might guess is the Primary Key field of tblParty)
 

HillTJ

To train a dog, first know more than the dog..
Local time
Today, 10:32
Joined
Apr 1, 2019
Messages
708
Thanks. I appreciate it. Trying to learn a bit more sql.
 

Users who are viewing this thread

Top Bottom