vba code to delete a single record from a table

Prayder

Registered User.
Local time
Today, 09:11
Joined
Mar 20, 2013
Messages
303
I currently have this code that opens a form when the button is pushed,
Code:
Private Sub cmdWorkOrder_Click()
On Error GoTo Err_cmdWorkOrder_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "New WorkOrder"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Forms![New WorkOrder].[Description of Work Performed] = Me.txtReasonCode

Exit_cmdWorkOrder_Click:
    Exit Sub

Err_cmdWorkOrder_Click:
    MsgBox Err.Description
    Resume Exit_cmdWorkOrder_Click
    
End Sub

I am wanting to add a line of code to this string that also deletes a record from a specified table. How would I go about doing that?
 
General approach:

Dim DeleteSQl as string 'dim a variable to hold an sql command
'
DeleteSQL = "Delete * from MyTable where RecordID =" & RecordIdOfRecToDelete

'execute the delete command
Currentdb.execute deleteSQL, dbFailOnError
 

Users who are viewing this thread

Back
Top Bottom