Skip to content
Advertisement

Why does “Enter parameter value” appears using INSERT INTO VALUES?

I’m always getting the “enter parameter value error” when I try to run this code. The error refers to idPat, idSP, idPar and measure_value. I have checked with the debug idPar, idPat, idSP and measure_value and they assume the correct value; the errors comes out when I run sql.

     Dim idPar As Integer
     Dim idPat As Integer
     Dim idSP As Integer
     Dim current_fc As String
     Dim namePar As String
     Dim sql As String
     Dim measureValue As Integer
    
    current_fc = TempVars!CurrentUsername
    namePar = Me.cmbManualDailyPar.Value
    measureValue = Me.txtMeasureValue

    idPar = Nz(DLookup("ID_par", "Parameter", "name_par = '" & namePar & "'"), 0)
    idPat = Nz(DLookup("ID_patient", "Patient", "fiscal_code = '" & current_fc & "'"), 0)
    idSP = Nz(DLookup("ID_SP", "Diagnosis", "ID_patient = " & idPat & ""), 0)

    
    sql = "INSERT INTO Measure(ID_par, measure_value,ID_SP,ID_patient)" & _
            " VALUES(idPar,measureValue,idSP,idPat);"
            
    DoCmd.RunSQL sql

Advertisement

Answer

Your VALUES part is just text. What you need is:

" VALUES(" & idPar & "," & measureValue & "," & idSP & "," & idPat & ")"

You may also need to enclose text values in database quotes, for example:

" VALUES(" & idPar & ", '" & measureValue & "'," & idSP & "," & idPat & ")"

to enclose measureValue if it is text.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement