b'h
i will be programmatically importing a text file into a table. i have saved the import steps. i will use this:
DoCmd.TransferText(TransferType, SpecificationName, TableName, FileName, HasFieldNames, HTMLTableName, CodePage)
to do the import.
this is what SpecificationName means:
Specification Name The specification name for the set of options that determines how a text file is imported, exported, or linked. For a fixed-width text file, you must either specify a specification name or use a schema.ini file, which should be stored in the same directory as the imported, linked, or exported text file.
i do need a specific specification; however i do not know how to specify one. when i manually imported a table, i did save the specifications for my import, however i do not know how to call this in the TransferText.
does anyone know how to specify SpecificationName ?
When you do the import manually, you can save the import options as a specification. You assign a name to the specification at the time you create it. In Access 2003, click the Advanced button on the Import Text Wizard. Then you will get a dialog for <filename> Import Specification; click the Save As button and assign a Specification Name ... for example "MySpec".
Use that name (in quotes) as the SpecificationName option for your DoCmd.TransferText command.
Related
I need to skip the first three lines of a CSV file when loading into MS Access. The default CSV import does not drop the first three lines. I am thinking of writing a macro to ignore the first three lines.
My research has shown the DoCmd object but its methods do not cater to drop the first x lines.
Any thoughts?
The DoCmd.TransferText method takes a SpecificationName as one of its arguments. Follow the instructions at How to Create an Import Specification to create and save an import specification.
Now go into Access Options, Navigation Options, and show hidden/system objects. You should now be able to open a table named 'mSysIMEXSpecs'. Find the import spec you created earlier based on the SpecName column. Change the 'StartRow' column for that import spec to 3 (the StartRow is zero-based).
Now you should be able to use the DoCmd.TransferText method passing the name of the import spec you created and it will skip your first three lines.
In Access VBA I would use two TextStream objects, one to .ReadLine the original CSV file line-by-line and the other to .WriteLine to a temporary file, skipping the first three lines of the input file. Do some web searches on Scripting.FileSystemObject and I'm sure you'll find some sample code for this.
Then I would use DoCmd.TransferText acImportDelim to import the temporary file into Access.
The Docmd.TransferText method is a good option to go with but as an alternative to modifying your import spec, you could consider importing everything and doing some validation after the import.
So you could, import the entire file and then use a delete query to delete data from the table.
As mentioned in a comment above, modifying the spec via a system table could be tricky for someone else to find where-as a delete query with a nice little comment in your code could work a treat. If it's required use it, if not it could be commented out.
I'm trying to manipulate a .csv file to remove text at the beginning of the file before the data starts. The file contains a fixed text string followed by a date field, which will change from file to file and then another fixed text string.
eg.
"Text1"
"------"
"date"
"Text2"
"data column1","data column2" etc
How can I remove this text so i can then use SSIS to import the data to the SQL database?
If I understand the question correctly you want to skip the first line of the file. When you set up the Flat file connection there is an option in the format section of the properties Header rows to skip:. You can set this to the number of rows you need to skip and the file should import. If you have a an actual header row you will need to skip that as well and then map the columns manually.
Within the SSIS import configuration, is there not an option to tell SSIS that the "first row has headers," or something roughly similar? That's what I've used when importing through SSIS, at least.
I am trying to use an automated macro to export a Ms-Access table to a csv file. I want the destination file to have a unique name, and I reckoned that using now()yyyymmddhhnn would be a good way to achieve this.
I have got transfer text working ok from my macro, and I have set up an export file spec for the transfer.
I am using ="C:\batchfile_" & Format(Now(),"yyyymmddhhnn") & ".csv" in the filename argument in the macro. This bit works.
But when I try to run the macro, it tells me that the filename doesn't exist and then the export doesn't complete. I am not sure why this is, but I think it is because the export file specification is expecting the destination file to have the same filename and column structure as the source table.
Does anyone know a way around this?
Eric
This is very old thread, I am posting my solution so that it may be usefull for some one else
transfer text works fine, as long as variables are supplied properly, you can check for other options other than filename, datasource alternatively create using file open statement
by opening text file and convert recordset data into CSV format.
I have a tab-delimited output from an outside program. One of the fields is (non-negotiable) is of #/#, that is 1/1, 1/2, 3/5 etc (represents part one of two, three of five etc).
Access is wrongly interpreting this as a date, where it needs to interpret it as a text. If I tell access to store it as a date (view the Type of field in the table) it still does not import properly.
How do I tell access, in the import stages, "interpret this field as TEXT"?
Assuming you are using the Import Wizard you should be able to specify the data type for each field in the source file. If it is a text file you can even create an "Import Specification" for the file where you indicate which fields to import and their data types. The import spec can be saved for future use if this will be a file format you need to work with in the future. You can also use the import spec via VBA if you use the Docmd.TransferText method.
I've had quite a hard time with this--can anyone help?
I need code for a command button that will import a file (the file will be different each time but will always be either txt. or csv), run an import specification that converts all data types to text (the spec is called SpecsTest), then call the table "Scrubbed" (not the original file name). I've also been unable to create a macro that works--the challenge has been that each time this is run the raw file name will be different.
Haven't used Access, but have done this a lot with Excel. Try this:
Dim ds As FileDialog
Set ds = Application.FileDialog(msoFileDialogOpen)
ds.Show
Dim path as String
path = ds.SelectedItems(1)
You'll have to add some check to ensure that a file was selected, etc, but this should get you on the right track.
BTW, you can configure default directories, filters, ... in the FileDialog so you should be able to limit the tendency of your users to screw up the import, but you never can tell.