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

Invalid SQL statement stemming from filename

P: 33
I have a file named:
Exec MIS Report.csv

When I attempt to import this into Access 2003, I recieve an error , "Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'."

I renamed the file to:
Executive MIS Report.csv

And now the file imports without a hitch. Is Exec a reserved word? Is Exec part of SQL?

Thank you!

-Kyle
May 20 '09 #1
Share this Question
Share on Google+
6 Replies


ADezii
Expert 5K+
P: 8,679
@servantofone
EXEC[UTE] is a Transact-SQL Reserved word which will execute a User Defined Function, a System Procedure, or a User-Defined Stored Procedure but I'm not sure if it has a bearing on your situation. Just for curiosity, have you tried Importing ExecMIS Report.csv without the Space?
May 21 '09 #2

P: 33
Just tried that... and Access imports it correctly. It only occurrs when the file is named Exec with a space after it. I have never experienced anything like this before. You can import the CSV file into Excel with the first filename, but Access will not. Well, I guess it doesn't really matter... I'll just use a different filename. Thanks for the info!
May 21 '09 #3

NeoPa
Expert Mod 15k+
P: 31,709
If you post in your actual code we can give a more precise answer without any guesswork.

I think you can assume that Exec is reserved though.
May 25 '09 #4

P: 33
NeoPa,

I'm not using any code. I'm right-clicking in the database window, selecting import for the menu, and then choosing a file that has Exec within the filename. This causes Access to generate the error prior to the wizard popping up.

-Kyle
May 26 '09 #5

NeoPa
Expert Mod 15k+
P: 31,709
Ah. I see.

I think this indicates a glitch in the Access code. Almost certainly related to a special case of "Exec ..." In the circumstances I can only suggest to avoid using it.
May 26 '09 #6

ADezii
Expert 5K+
P: 8,679
@servantofone
It took me a little while, but I did come up with what may be a workable solution, the 'Base Code' of which I'll post for you. Basically, if the Filename contains 'Exec ' it is converted and Renamed to 'Exec_', the Import occurs without any problems, and the User is notified of this process. If the Filename does not contain 'Exec ', it is Imported normally. It is up to you as to whether or not it is a viable Option:
Expand|Select|Wrap|Line Numbers
  1. Public Function fImportCSVFile(strFileName As String)
  2. Dim strNewName As String
  3.  
  4. If InStr(strFileName, "Exec ") > 0 Then     'does "Exec " appear in the File Name
  5.   strNewName = Replace(strFileName, "Exec ", "Exec_")
  6.     Name strFileName As strNewName      'Rename the File replqacing Exec  with Exec_
  7.       DoCmd.TransferText acImportDelim, , "CSV Table", strNewName, False
  8.       MsgBox strFileName & " has been Renamed to " & strNewName & " in order to avoid " & _
  9.                            "Import Errors", vbExclamation, "Change in File name"
  10. Else
  11.   DoCmd.TransferText acImportDelim, , "CSV Table", strFileName, False
  12. End If
  13. End Function
To successfully Import a File with 'Exec ' contained within its Name:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fImportCSVFile("C:\Dezii\Exec Test.csv")
May 26 '09 #7

Post your reply

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