Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Execute SQL (97-XP)

    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?

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Execute SQL (97-XP)

    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.
    Wendell

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Execute SQL (97-XP)

    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 & ");"
    Charlotte

  4. #4
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Execute SQL (97-XP)

    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

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Execute SQL (97-XP)

    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.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •