Error in entering the information filled in the form. When clicking the save button (without form), it generates an error 3075 - Problems in the query (1 Viewer)

caiomuniz

New member
Local time
Today, 17:24
Joined
Feb 2, 2020
Messages
2
People I am creating a button to add information to a table (tbCadastro), from the information entered in the form. To do this, create an SQL statement:

Private Sub cmdSalvar_Click()​
CurrentDb.Execute "INSERT INTO tbCadastro(Requisição, Código, Cliente, CPF_CNPJ, ID_Cartao, ValorDisponivelCartao, ValorBrutoDevolucao, Tarifa, ValorLiquido, Motivo, Observacoes, DataPagamento, FormaPagamento, BancoCredito, AgenciaCredito, ContaCredito, BancoDebito, AgenciaDebito, ContaDebito)" & _​
"VALUES(" & Me.Requisição & ",'" & Me.Cliente & "','" & Me.CPF_CNPJ & "','" & Me.ID_Cartao & "','" & Me.ValorDisponivelCartao & "','" & _​
Me.Tarifa & "','" & Me.ValorBrutoDevolucao & "','" & Me.ValorLiquido & "','" & Me.Motivo & "','" & Me.Observacoes & "','" & _​
Me.DataPagamento & "','" & Me.FormaPagamento & "','" & Me.BancoCredito & "','" & Me.AgenciaCredito & "','" & Me.ContaCredito & "','" & _​
Me.BancoDebito & "','" & Me.AgenciaDebito & "','" & Me.Requisição & "',' & Me.ContaDebito & " ')"​
End Sub​




After filling out all the fields in the form and clicking the Save button, it generates an error: "Syntax error (operator missing) in query expression" Balance Return ""

This information (balance return, etc.) is inside a combo box, where the user selects when filling out the form.

Thanks!!
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:24
Joined
May 21, 2018
Messages
8,529
If you did this
Code:
dim strsql as string
strSql =
"INSERT INTO tbCadastro(Requisição, Código, Cliente, CPF_CNPJ, ID_Cartao, ValorDisponivelCartao, ValorBrutoDevolucao, Tarifa, ValorLiquido, Motivo, Observacoes, DataPagamento, FormaPagamento, BancoCredito, AgenciaCredito, ContaCredito, BancoDebito, AgenciaDebito, ContaDebito)" & _
"VALUES(" & Me.Requisição & ",'" & Me.Cliente & "','" & Me.CPF_CNPJ & "','" & Me.ID_Cartao & "','" & Me.ValorDisponivelCartao & "','" & _
Me.Tarifa & "','" & Me.ValorBrutoDevolucao & "','" & Me.ValorLiquido & "','" & Me.Motivo & "','" & Me.Observacoes & "','" & _
Me.DataPagamento & "','" & Me.FormaPagamento & "','" & Me.BancoCredito & "','" & Me.AgenciaCredito & "','" & Me.ContaCredito & "','" & _
Me.BancoDebito & "','" & Me.AgenciaDebito & "','" & Me.Requisição & "',' & Me.ContaDebito & " ')"

debug.print strSql
It will be pretty obvious what the mistakes are. The spacing alone will fail
 

caiomuniz

New member
Local time
Today, 17:24
Joined
Feb 2, 2020
Messages
2
@MajP Execution error 438 persists

'The object does not accept this property or method'
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:24
Joined
May 21, 2018
Messages
8,529
@MajP Execution error 438 persists

'The object does not accept this property or method'
Nice cryptic response. That is a completely meaningless statement. You get a bizarre error without showing where the error is located. If you want help you have to at least try.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:24
Joined
May 7, 2009
Messages
19,245
why not used a Bound Form?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:24
Joined
Feb 28, 2001
Messages
27,188
With the limited information you have presented, I have to suggest that you have messed up your quoting somewhere. MajP's suggestion to make an SQL string first and Debug.Print it was a way to see what you had built. If it wasn't what you intended, that fact would stand out immediately because the statement would be missing something.

That reference to a control name that doesn't appear in the INSERT INTO query means you have tried to indirectly reference something and didn't get it quite right. When you get errors with substitution and concatenation, I have to think that something that should have been quoted wasn't quoted, or something that shouldn't have been quoted was quoted.

Given how much (how little) you have given, that's my best shot subject to amendment if more information is offered.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:24
Joined
May 7, 2009
Messages
19,245
it is easier to use QueryDef object when Updating/Inserting records:
Code:
Private Sub cmdSalvar_Click()
dim db As DAO.Database
Dim qd As DAO.QueryDef
dim SQL As String
Set db = Currentdb
SQL= "INSERT INTO tbCadastro([Requisição], [Código], [Cliente], [CPF_CNPJ], [ID_Cartao], [ValorDisponivelCartao]," & _
"[ValorBrutoDevolucao], [Tarifa], [ValorLiquido], [Motivo], [Observacoes], [DataPagamento], [FormaPagamento]," & _
"[BancoCredito], [AgenciaCredito], [ContaCredito], [BancoDebito], [AgenciaDebito], [ContaDebito]) "
SQL = SQL & _
"SELECT P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18;"
Set qd = db.CreateQueryDef("", SQL)
With qd
.Parameters(0) = Me.[Requisição]
.Parameters(1) = Me.[Código]
.Parameters(2) = Me.[Cliente]
.Parameters(3) = Me.[CPF_CNPJ]
.Parameters(4) = Me.[ID_Cartao]
.Parameters(5) = Me.[ValorDisponivelCartao]
.Parameters(6) = Me.[ValorBrutoDevolucao]
.Parameters(7) = Me.[Tarifa]
.Parameters(8) = Me.[ValorLiquido]
.Parameters(9) = Me.[Motivo]
.Parameters(10) = Me.[Observacoes]
.Parameters(11) = Me.[DataPagamento]
.Parameters(12) = Me.[FormaPagamento]
.Parameters(13) = Me.[BancoCredito]
.Parameters(14) = Me.[AgenciaCredito]
.Parameters(15) = Me.[ContaCredito]
.Parameters(16) = Me.[BancoDebito]
.Parameters(17) = Me.[AgenciaDebito]
  .Parameters(18) = Me.[ContaDebito]
  .Execute
End With
Set qd = Nothing
Set db = Nothing


End Sub
 

Users who are viewing this thread

Top Bottom