Make table RunSQL using a variable for the new table name.

  • Thread starter Thread starter Gene
  • Start date Start date
G

Gene

I'm trying to run a make table SQL where the field
CodeName is a variable and the name of the new table is a
variable

Dim gbTableName As String

gbTableName = "RESP"

DoCmd.RunSQL "SELECT Link.CodeName, Link.CodeValue,
Link.Description, Link.SortOrder INTO '" & gbTableName
& "' FROM Link WHERE (((Link.CodeName)=[Forms]![Form1]!
[Text2]));"

When I run this I get the following error:
"Run-time error '3450': Syntax error in query. Incomplete
query clause."

I get the same error when I run it as this:

DoCmd.RunSQL "SELECT Link.CodeName, Link.CodeValue,
Link.Description, Link.SortOrder INTO ' & gbTableName & '
FROM Link WHERE (((Link.CodeName)=[Forms]![Form1]!
[Text2]));"

When I run it like this
DoCmd.RunSQL "SELECT Link.CodeName, Link.CodeValue,
Link.Description, Link.SortOrder INTO & gbTableName & FROM
Link WHERE (((Link.CodeName)=[Forms]![Form1]![Text2]));"

I get the following error:
"Run-time error '3141': The SELECT statement includes a
reserved work or an argument name that is misspelled or
missing, of the punctuation is incorrect."


Is possible to do what I am trying to do?
Thank you.
Gene
 
Try taking out the single quotes but leave the double
quotes:

DoCmd.RunSQL "SELECT Link.CodeName, Link.CodeValue,
Link.Description, Link.SortOrder INTO " & gbTableName
& " FROM Link WHERE Link.CodeName =[Forms]![Form1]!
[Text2];"
 
No that gives you the same error

"Run-time error '3450': Syntax error in query.
Incomplete query clause."

I should have included that in my original post, sorry.

Gene
-----Original Message-----
Try taking out the single quotes but leave the double
quotes:

DoCmd.RunSQL "SELECT Link.CodeName, Link.CodeValue,
Link.Description, Link.SortOrder INTO " & gbTableName
& " FROM Link WHERE Link.CodeName =[Forms]![Form1]!
[Text2];"
-----Original Message-----
I'm trying to run a make table SQL where the field
CodeName is a variable and the name of the new table is a
variable

Dim gbTableName As String

gbTableName = "RESP"

DoCmd.RunSQL "SELECT Link.CodeName, Link.CodeValue,
Link.Description, Link.SortOrder INTO '" & gbTableName
& "' FROM Link WHERE (((Link.CodeName)=[Forms]![Form1]!
[Text2]));"

When I run this I get the following error:
"Run-time error '3450': Syntax error in query. Incomplete
query clause."

I get the same error when I run it as this:

DoCmd.RunSQL "SELECT Link.CodeName, Link.CodeValue,
Link.Description, Link.SortOrder INTO ' & gbTableName & '
FROM Link WHERE (((Link.CodeName)=[Forms]![Form1]!
[Text2]));"

When I run it like this
DoCmd.RunSQL "SELECT Link.CodeName, Link.CodeValue,
Link.Description, Link.SortOrder INTO & gbTableName & FROM
Link WHERE (((Link.CodeName)=[Forms]![Form1]![Text2]));"

I get the following error:
"Run-time error '3141': The SELECT statement includes a
reserved work or an argument name that is misspelled or
missing, of the punctuation is incorrect."


Is possible to do what I am trying to do?
Thank you.
Gene

.
.
 
Back
Top