Tony Toews wrote:
> On Tue, 22 May 2012 07:36:02 -0700 (PDT), colmkav
> <
colm...@yahoo.co.uk> wrote:
>
>> I am trying to write an Access query where I choose the tablename the
>> results will be output to.
>
> Why not create a SQL string with all the relevant portions of the
> query and execute it directly.
>
> strSQL = "INSERT INTO <tablename> ( <fieldname>, ... )" & _
> "VALUES (<value>, ...);"
> currentdb.Execute strSQL, dbFailOnErrors
>
> Much easier to work with and debug.
>
Putting aside the issue that parameters cannot be used for the OP's task, I
disagree that dynamic sql is easier to work with and debug than using
parameterized queries. Using parameters relieves the developer from the
odious task of making sure values are properly delimited as well as the more
odious task of escaping special characters in strings to force them to be
treated literally.
But of course, it comes down to developer style and what the developer is
used to doing ... and where he is doing it. With an external application
using ADO to access a Jet database backend, given the choice of
strSQL = "INSERT INTO <tablename> ( <fieldname>, ... )" & _
"VALUES (<value>, ...);"
cn.execute sql
vs.
cn.savedquery parm1, parm2, parm3
I will definitely choose the latter.