Can't get Delete query to work.. Please help.

hardrock

Registered User.
Local time
Today, 23:14
Joined
Apr 5, 2007
Messages
166
Hi All,

I am trying to write a delete query that must have 2 conditions met before it removes the record from the table tblPO. P1 and L1 values are read from textboxes on my form, and only display values if a record in my table contains them. I would select my record from a listbox to populate P1 and L1


DoCmd.RunSQL ("DELETE * FROM tblPO WHERE PURCHASEORDER = '" & P1 & "' AND LINEITEM = '" & L1 & "';")

I simply cannot get this to work, have tried it with and without quotes, but nothing any ideas?
 
Change the Form control Names P1 and L1 to refer to form field. Modified SQL is given below:

Code:
DoCmd.RunSQL ("DELETE * FROM tblPO WHERE PURCHASEORDER = '" & Me![P1] & "' AND LINEITEM = '" & Me![L1] & "';")

If you need to look at the data before executing the Delete SQL then you must create a SELECT Query and change it's SQL with the above criteria and open it in Datasheet View or take a DCount("*","QueryName") and check to determine the presence of records for deletion.
 
What error message do you get?
Check your tblPO and confirm the field names and datatypes and let us know what you found.
 

Users who are viewing this thread

Back
Top Bottom