Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003

    Red face Unanswered: how do I save a text file as a query in access

    I created a string that is a sql statement in Microsoft Access 2000 and I tried to run it using docmd.runsql, but I get the following error message :"runsql action reqires an argument consisting of an SQL statement". I believe it is because the sql statement is too long (over 256 characters) as when I output the statement to a file and copy the file into the sql editor in access it runs fine. If I output the sql to a file, how do I import the sql as a query so that I can run it.

    I guess my question is how do you run sql stored in a text file in code and if I want to base a form off of the results of the sql stored in the file (c:/cdd.txt) how do I do that??

    Please someone help!!!


  2. #2
    Join Date
    Jul 2002
    RunSQL action or method is designed to run ACTION 'queries': update, insert, delete.

    From your description, you have a Select statement.
    Select statements are used in recordsets (results are NOT displayed) or saved as queries and run with DoCmd.OpenQuery (results are displayed).


  3. #3
    Join Date
    Aug 2003
    That Wasn't much help DannyY,

    kxa you will need to change your SQL statement to an append or create statement,

    "INSERT INTO [New Table] ({list of fields}) SELECT {List Of Fields} FROM [Table Name]" Append SQL

    "SELECT {List Of Fields} INTO [New Table] FROM [Table Name] Create SQL

    Both of these Should work with the DoCmd.RunSQL, I tend to use dbs.execute

    I would recommend the Append SQL therefore allowing you to create a form in design view which displays the results of your DoCmd.RunSQL. In other words create a table with the list of fields that are gonna be sent from the vba code, then create your form to display these fields. When the code is executed and the form is activated the results will be displayed.

    Danny K

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts