Deleting from a query that is displayd in the form.

Ankarn

Registered User.
Local time
Today, 14:21
Joined
Jul 4, 2008
Messages
81
I have a form where i display results from a query, with buttons in the header, one of the buttons is "delete all" which is supposed to be deleting all the records in the query.

I have a problem with this and it seems to be because it is displayd in the form by continous forms.

here is the code:

Code:
Private Sub Kommando19_Click()
Dim strMsg As String
Dim strSql As String
strMsg = "Du er i ferd med å slette alle de valgte elementene" + vbCrLf + vbCrLf
strMsg = strMsg + "Fortsette?"
If MsgBox(strMsg, vbQuestion + vbYesNo, "Slette?") = vbYes Then
    strSql = "DELETE Query1. * FROM Query1"
    CurrentDb.Execute strSql
End If

End Sub
 
I believe your probelm is that you're trying to delete records from a Query. To the best of my knowledge, a SQL Delete statement only applies to deleting records from Tables.
 
I dont think thats the case, since i am able to edit in a query, and in that way edit it in the table.
 
Is the query you are using updateable? I know you said you can edit in a query (I agree) but can you edit in this query?
 
You can edit a record in a table using a query and you can delete a record in a table using a query, but you cannot delete a record from a query! Substitute the table name for the query name.

Code:
DELETE FROM [B]table_name[/B]
WHERE column_name = some_value
 

Users who are viewing this thread

Back
Top Bottom