Invalid SQL statement stemming from filename

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • servantofone
    New Member
    • Apr 2008
    • 33

    #1

    Invalid SQL statement stemming from filename

    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
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by servantofone
    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
    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?

    Comment

    • servantofone
      New Member
      • Apr 2008
      • 33

      #3
      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!

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        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.

        Comment

        • servantofone
          New Member
          • Apr 2008
          • 33

          #5
          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

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            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.

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              Originally posted by servantofone
              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
              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:
              Code:
              Public Function fImportCSVFile(strFileName As String)
              Dim strNewName As String
              
              If InStr(strFileName, "Exec ") > 0 Then     'does "Exec " appear in the File Name
                strNewName = Replace(strFileName, "Exec ", "Exec_")
                  Name strFileName As strNewName      'Rename the File replqacing Exec  with Exec_
                    DoCmd.TransferText acImportDelim, , "CSV Table", strNewName, False
                    MsgBox strFileName & " has been Renamed to " & strNewName & " in order to avoid " & _
                                         "Import Errors", vbExclamation, "Change in File name"
              Else
                DoCmd.TransferText acImportDelim, , "CSV Table", strFileName, False
              End If
              End Function
              To successfully Import a File with 'Exec ' contained within its Name:
              Code:
              Debug.Print fImportCSVFile("C:\Dezii\Exec Test.csv")

              Comment

              Working...