Solved SQL Error

sergio vieira

Member
Local time
Today, 03:12
Joined
Apr 22, 2024
Messages
35
Good morning, dear friends. I have this SQL statement, which gives me a missing operator error. Does anyone know what is going on? I appreciate your help.

strSQL = "SELECT detinquilino.ArtigoMatricial, detinquilino.Fração, detinquilino.Data, detinquilino.OPeração, detinquilino.Entidade, detinquilino.Retenção, detinquilino.SubTotal, detinquilino.Neutro, detinquilino.Total From detinquilino"
strSQL = "DELETE * FROM detinquilino WHERE ArtigoMatricial = " & Me.txtArtigoMatricial
DoCmd.RunSQL strSQL
 
Which one? :( Something has been interpreted to be an emoji. You SHOULD post sql code within code tags.

Strings need to be surrounded by single quotes ' unless it contains a single quote, then triple double quotes works, I think?

Date literals with # and in mm/dd/yyyy or yyyy-mm-dd format

Numbers do not need anything
Also for anything other than one item of criteria, I tend to put the the criteria into a string variable and then debug.print it, until correct then also use that in the code.

Added benefit is, if you still cannot see the error, you can copy and paste back here the output from the debug.print for someone else to spot it. :)
 
Without tags like?
??????????

With tags
Code:
strSQL = "SELECT detinquilino.ArtigoMatricial, detinquilino.Fração, detinquilino.Data, detinquilino.OPeração, detinquilino.Entidade, detinquilino.Retenção, detinquilino.SubTotal, detinquilino.Neutro, detinquilino.Total From detinquilino"
strSQL = "DELETE * FROM detinquilino WHERE ArtigoMatricial = " & Me.txtArtigoMatricial
debug.print strsql

DoCmd.RunSQL strSQL

Test each in the immediate window after making a backup.
 
1742985216946.png
 
What is the point of the SELECT statement?

DoCmd.RunSQL only works with action queries.

It can only run a single statement on each call.
 
gives me a missing operator error

While there can be many reasons for this, the most common error is (a) improper or unbalanced quotes (including a lack of quoting) of some literal value that contains spaces or tabs, or (b) improper, unbalanced, or a lack of bracketing of something that contains spaces or tabs. The VBA language threats spaces and tabs as a syntax delimiter. Although it doesn't appear to apply in your case, a badly placed parenthesis could also trigger the error even if the parenthesis has an appropriate paired parenthesis.

For example, let's say you have a field named MY NAME. To actually USE that, it needs to be bracketed as [MY NAME] because otherwise, VBA would want to treat that as TWO fields, one named MY and the other named NAME - and two fields need to be separated by an operator like + or & or AND or something like that.
 
strSQL = "DELETE * FROM detinquilino WHERE ArtigoMatricial = " & Me.txtArtigoMatricial

As Me.TxtArtigoMartirial looks to be text from the error code, this should be

strSQL = "DELETE * FROM detinquilino WHERE ArtigoMatricial = '" & Me.txtArtigoMatricial &"'"

Please take a look at the example at https://www.w3schools.com/sql/sql_delete.asp
 

Users who are viewing this thread

Back
Top Bottom