delete record

deb

Active Member
Joined
Feb 1, 2003
Messages
400
Acess 365

I have a form called vendor (shows a list of Vendors), with a subform called VendorVariable (to add a Vendor that is in the t_Vendor table to the t_VendorVariable table. I then want the Vendor added to the t_VendorVariable table via the subform to delete the same Vendor from the t_Vendor Table.

I am trying to end up with two tables separating the Vendors with the similiarly named vendors....
FYI the Vendors added to the t_VendorVariable table via the subform are Vendors that are the same but are spelled differently. i.e. st.Joseph and Saint Joseph.

When I add a record in the subform I want it to automatically delete the Vendor record from the t_Vendor table where the VendorVariable is the one just added via the subform.

In other words if a new Vendor record is added to t_VendorVariable, the vendor with the same name should be deleted from the t_Vendor table.

How and where do I add the delete code?

I tried putting at the save button of the subform. I pops up a "Enter Parameter Value" box for the Vendor Name that was entered

Private Sub btnSave_Click()
On Error GoTo btnSave_Click_Err

On Error Resume Next
DoCmd.RunCommand acCmdSaveRecord
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If

DoCmd.SetWarnings False
strSQL = "Delete * From t_Vendor WHERE Vendor= " & Me.VendorVariation.Value
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
strings in raw sql must be quoted.
Code:
strSQL = "Delete * From t_Vendor WHERE Vendor= " & "'" & Me.VendorVariation.Value & "'"
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top