Thank you for the quite useful tip. I tried the command and it brings up the wizard. Now it is necessary to create a task which is probably a batch file where the initial parameters are stored so that the user can simply run it. However due to whatever reason I get the error message " The Outlook task can not be created". My purpose is to have just a simple batch file executing the wizard. Can please anyone point to the right direction? How should this kind of job be approached? Thanks.Have a look at DoCmd.TransferText
If I run the codeThe Import Spec is stored in your database. It's simply a template for your import.
Run the import once with all your configurations, save it as a spec, run it again -> use the already saved spec.
Through the Import/Export Wizard you'll find where to save as a Specification.
Dim Forname As String, OriginTbl As String, CSVInput As String, Proc As String
CSVInput = "OrInput.csv"
OriginTbl = "OriginalTbl"
Proc = "ImpBank"
If fExistTable(OriginTbl) = True Then
DoCmd.DeleteObject acTable, OriginTbl
End If
DoCmd.TransferText acImportDelim, Proc, OriginTbl, CSVInput, True
I googled this message. Microsoft says it is a known problem. They propose solutions first is using Access 2007 which I do not have, second gives a link to the same article which is useless and the third is a quite complicated long process. Now could anyone help please.Access 2010 Error: "The text file specification '<number>' does not exist. You cannot import, export, or link using the specification"
Set fs = CreateObject("Scripting.FileSystemObject")
Set TxtFile = fs.opentextFile(SrcFile, 1, 0)
If RStP.Fields("SysHasFieldNames") = True Then S = TxtFile.readline
While Not TxtFile.AtEndOfStream
If Len(Nz(RStP!SysRange)) > 0 Then
delim = left(RStP!SysRange, 1)
Else
delim = "'"
End If
If delim = "T" Then delim = Chr(9)
If Len(RStP!SysRange) > 1 Then qualifier = Mid(RStP!SysRange, 2, 1) Else qualifier = """"
srcfields = "'" & Replace(Replace(TxtFile.readline, "'", "''"), delim, "','") & "'"
sqlStr = "INSERT INTO impTable VALUES (" & srcfields & ")"
CurrentDb.Execute sqlStr
Wend
Two things:
1. Just as the error message states, it can't find the import spec meaning that you haven't created the import spec. An import spec can be created by clicking the Advanced button at the bottom of the wizard. See here:
http://www.btabdevelopment.com/ts/default.aspx?PageId=25
2. You've just entered a file name without the full path to the file. I know that it's called a Wizard but it's not that clever
Get this working and I'll give you another tip.
If the following conditions are met:It works. Thanks. What is the other tip?
you can also use the openastextstream method - see this link
http://msdn.microsoft.com/en-us/library/aa265341(v=vs.60).aspx
you can then loop through the file, reading each row and then use a bit of sql to insert the row into a table.
Benefit is that you don't need an import specification as such, but still need to know the file structure (field delimiters, text qualifiers, has headings) to import the data.
Here is a code snippet - my preference is to insert data to a temporary table where all fields are text, then insert data into the relevant tables (I frequently get sent reports in flat file or 'worksheet ' form and need to import different parts of it to different tables
Code:Set fs = CreateObject("Scripting.FileSystemObject") Set TxtFile = fs.opentextFile(SrcFile, 1, 0) If RStP.Fields("SysHasFieldNames") = True Then S = TxtFile.readline While Not TxtFile.AtEndOfStream If Len(Nz(RStP!SysRange)) > 0 Then delim = left(RStP!SysRange, 1) Else delim = "'" End If If delim = "T" Then delim = Chr(9) If Len(RStP!SysRange) > 1 Then qualifier = Mid(RStP!SysRange, 2, 1) Else qualifier = """" srcfields = "'" & Replace(Replace(TxtFile.readline, "'", "''"), delim, "','") & "'" sqlStr = "INSERT INTO impTable VALUES (" & srcfields & ")" CurrentDb.Execute sqlStr Wend
If you want to look at import specifications, look in your system tables for MsysIMEXSPecs (which is delim information) and MsysIMEXColumns (which relates to each column).
Prior to importing anything using the wizard these tables do not exist - they are created when you create an import specification. Note that although you can create these tables yourself, Access will not recognise it. However, once created by Access you can add new records.