I am trying to UPDATE some fields in my table in Access VBA

I need help with this, I'm sorry, I'm new to VBA, and I'm trying to run an update request, which should get the value from a variable and update an existing table. This is done using VBA. When executing, an error message is not displayed, but the table is not updated with the new value. The code is as follows:

Query = "UPDATE Results " & _
        "SET fk_Report='" & Report & "'" & _
            ",fk_Name='" & Namevar & "'" & _
            ",fk_Age='" & Agevar & "'" & _
            ",fk_Sex='" & Sexvar & "'" & _
        "WHERE [Count]='" & Countvar & "'" & _
            ",[Positives]='" & Posvar & "'" & _
            ",[Negatives]='" & Negvar & "'" & _
            ",[Unknow]='" & Unkvar & "';"
    CurrentDb.Execute (Query)

If someone can help ...

+3
source share
2 answers

You don't need commas in the where clause

Query = "UPDATE Results " & _
    "SET fk_Report='" & Report & "'" & _
        ",fk_Name='" & Namevar & "'" & _
        ",fk_Age='" & Agevar & "'" & _
        ",fk_Sex='" & Sexvar & "'" & _
    "WHERE [Count]='" & Countvar & "' " & _
        "AND [Positives]='" & Posvar & "' " & _
        "AND [Negatives]='" & Negvar & "' " & _
        "AND [Unknow]='" & Unkvar & "';"
CurrentDb.Execute (Query)
+1
source

use AND instead, (comma) after WHERE clause

0
source

All Articles