Solved New access user, Access UPDATE Error 3464 Data type mismatch in criteria expression (1 Viewer)

Versus

New member
Local time
Yesterday, 21:57
Joined
May 24, 2020
Messages
5
Hello everyone first time here i'm starting to learn access and i'm having a problem with the SQL update function,


Code:
Private Sub GerarRequisicao()
    
    If Me.txt_oculto = "Existente" _
    Then
    
    Dim Comando As String
    Dim DataSaida As Date
    Dim CodigoREQ As Integer
    
    DataSaida = Me.txt_DataSaidaRequisicao
    CodigoREQ = Me.txt_CodigoRequisicao
    
    Comando = "UPDATE tabela_requisicao SET DataSaidaRequisicao = '" & DataSaida & "'" & _
    "WHERE CodigoRequisicao = '" & CodigoREQ & "'"
    
    db.Execute (Comando)
    
    ''Error is above in the then ^^
    
    Else
    cmd = "INSERT INTO tabela_requisicao(DataSaidaRequisicao,DataRetornoRequisicao,LocalRequisicao,ResponsavelRequisicao)VALUES('" & Me.txt_DataSaidaRequisicao & "', '" & Me.txt_DataRetornoRequisicao & "', '" & Me.txt_LocalRequisicao & "', '" & Me.txt_ResponsavelRequisicao & "')"
    db.Execute (cmd)
    MsgBox ("Requisição criada com sucesso"), vbInformation + vbOKOnly
    
    End If
    
End Sub


"WHERE CodigoRequisicao = '" & CodigoREQ & "'"

When I try to compare "CodigoRequisicao" which is a field of type auto incrementable (in a table I own) with "CodigoREQ" which is a integer type variable i get the error:
"Error 3464 Data type mismatch in criteria expression"

Thank you all for your attention :)

What can i do to solve this error?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:57
Joined
Oct 29, 2018
Messages
13,766
Hi. Welcome to AWF!

Since the field is a Number data type, you don't need to delimit the value with single quotes. Try simply using:

" WHERE CodigoRequisicao = " & CodigoREQ

Hope that helps...
 

Versus

New member
Local time
Yesterday, 21:57
Joined
May 24, 2020
Messages
5
Thank you very much, you helped me a lot :)
 

Users who are viewing this thread

Top Bottom