By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,880 Members | 1,430 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,880 IT Pros & Developers. It's quick & easy.

select into statement to transfer data into table frm sql query

P: 16
I have one variable strsql declared as string
this is just like strsql= "select* from blabla....."&"bllalal"
I have another table tbl_temp which has all the fileds selected in strsql query
I want to move all the data into tbl_temp from strsql query
I am trying to do:--
DoCmd.RunSQL ("insert* into tbl_temp from strsql")

it gives rutime error 2757
There was a problem accessing a property or method of the
OLE object.
Sep 12 '08 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 2.5K+
P: 2,545
Hi Sam12. Not surprised there is an error message, as your syntax is incorrect in at least three ways - in your INSERT INTO itself and in your use of the strSQL variable within it.

Look up the INSERT INTO syntax in the help, or use the Access query builder to give you an example of it.

There are two forms of the statement: one in which you can specify the field order, and one in which the order of the fields is inferred. You can also specify the values directly in the statement, or use a SELECT to do so.

The general syntax is
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO sometable (field1, field2, ..., fieldN)
  2. VALUES (value1, value2, ... , valueN);
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO sometable (field1, field2, ..., fieldN)
  2. SELECT stuff FROM anothertable;
Also, you cannot refer to the strSQL variable within the INSERT statement as you have shown - you have to concatenate the strings so that the database engine has a true SQL statement to work upon, not an attempt to pass a reference to a VBA variable that it knows nothing about.

Sep 12 '08 #2

P: 16
Thanks stewart
i did it by recordset method with do while loop
Thanks again for replying
Sep 12 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.