2
votes

Using VBA I'm trying to perform a SELECT INTO following the documentation here: https://msdn.microsoft.com/en-us/library/bb208934(v=office.12).aspx

I'm attempting to select from a query and insert into a new table:

strSQL = "SELECT [BookingDate], [StartTime], [first_name], [last_name] INTO [NewTable] FROM myQuery"
    CurrentDb.Execute strSQL, dbFailOnError

However it's throwing an error

Too Few Parameters : Expected 1

What am I doing wrong?

1
This typically indicates a misspelled or missing field name.Gustav
I tried strSQL = "SELECT * INTO [NewTable] FROM myQuery" to start with but was getting exactly the same error.Chris Nevill
Then your query needs a parameter. If you filter on a form field, that will be the case.Gustav
Try to remove them for a test. If that runs, you must find other methods to apply the values from your TempVars.Gustav
Andre's solution using DoCmd provided the answer which allows usage of TempVarChris Nevill

1 Answers

4
votes

From https://books.google.de/books?id=JgBe3OMEoU8C&lpg=PA517&ots=hm-yKG68cy&dq=Db.Execute%20tempvars&pg=PA517#v=onepage&q&f=true

Caution

The TempVar scope is defined by the Application object, which includes any of its children such as forms, reports, and queries.

The database engine, however, is outside of the application scope. [...]

Also if you use the CurrentDb object to execute a query, that query will run outside of the application scope. Instead, use DoCmd.OpenQuery to execute the query and it will have access to your TempVars.

Or alternatively, DoCmd.RunSQL see http://www.utteraccess.com/forum/index.php?showtopic=1949829