select into statement to transfer data into table frm sql query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sam12
    New Member
    • Apr 2008
    • 16

    select into statement to transfer data into table frm sql query

    I have one variable strsql declared as string
    this is just like strsql= "select* from blabla....."&"b llalal"
    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.
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    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
    Code:
    INSERT INTO sometable (field1, field2, ..., fieldN)
    VALUES (value1, value2, ... , valueN);
    or
    Code:
    INSERT INTO sometable (field1, field2, ..., fieldN)
    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.

    -Stewart

    Comment

    • sam12
      New Member
      • Apr 2008
      • 16

      #3
      Thanks stewart
      Done!
      i did it by recordset method with do while loop
      Thanks again for replying

      Comment

      Working...