Remove or Delete?

HowardChr

Noob
Local time
Today, 12:59
Joined
Apr 26, 2007
Messages
35
I know the command "CurrentDb.Execute "INSERT INTO [Input] ([Loc_Desc])
VALUES (""" & Me.List12 & """)", dbFailOnError" works. I now need a way to
delete a value from a table using a similar command. I am wandering if there
is a "REMOVE FROM" or "DELETE" or something similar that will take an option from List12 out of a Table named "Input". Thanks again for your help!
 
Howard,

Depends on your Primary Key name and data type.

Code:
DoCmd.RunSQL "Delete From Input Where PrimaryKey = " & Me.List12        <-- Numeric Key
DoCmd.RunSQL "Delete From Input Where PrimaryKey = '" & Me.List12 & "'" <-- Character Key

Don't try it without the Where clause ... all data will disappear

hth,
Wayne
 
This appears to help... One more problem though. When I try to execute this, there is a pop up asking for me to input a Primary Key. Right now, I have the primary key as an autonumber format. The entire table has ID (AutoNumber), and and Location (Text).

Code:
DoCmd.RunSQL "Delete From Input Where PrimaryKey = '" & Me.List0 & "'"
 
you need to change primarykey to ID

Code:
DoCmd.RunSQL "Delete From Input Where [B]ID[/B] = '" & Me.List0 & "'"
 
Howard,

"Depends on your Primary Key name and data type."

If your table only has the ID field, then I hope that your listbox has
ID, Description, with ID possibly (probably) hidden.

DoCmd.RunSQL "Delete From Input Where id = " & Me.List12.Column(0)

Or

DoCmd.RunSQL "Delete From Input Where [Loc_Desc] = '" & Me.List12 & "'"

Need more info as to table structure and listbox contents to give a
definitive answer.

Wayne
 

Users who are viewing this thread

Back
Top Bottom