• Execute SQL (97-XP)

    Author
    Topic
    #420706

    I am running the following lines of code and the execute line errors with 3061 Too few Parameters.Expected 1.

    SQL1 = “INSERT INTO tblLocalOption (Option_Name) VALUES (strOption);”

    CurrentDb.Execute SQL1, dbFailOnError

    what do I need to do to make this line work?

    Viewing 1 reply thread
    Author
    Replies
    • #953452

      We don’t know what your table structure for tblLocalOption looks like, so I can’t judge whether your SQL statement is correct. I typically do this by designing the query in the query design grid, and then switching to the SQL view to see how it constructed the string. You might also want to look at this MSDN Article on the syntax of Jet SQL queries. Note that there is also a more advanced one in the same series.

    • #953464

      If strOption is supposed to represent a variable, it needs to be concatenated into the SQL statement. Otherwise, the query engine assumes it’s a parameter and expects you to pass a value for it. Try this:

      SQL1 = “INSERT INTO tblLocalOption (Option_Name) VALUES (” & strOption & “);”

      • #953465

        Thanks Charlotte,
        That didn’t work but it pointed me in the right direction – this did –

        SQL1 = “INSERT INTO tblLocalOption (Option_Name) VALUES (” & Chr(34) & strOption & Chr(34) & “);”

        thanks

        • #953466

          Yes, if the value in the variable should be a string, then you need to concatenate the quotes around it unless they’re already in the variable. Glad you got it working.

    Viewing 1 reply thread
    Reply To: Execute SQL (97-XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: