import csv file to Access 2007 using VBA

I am having difficulty importing a .csv file to Access 2007. The file will import using the transfertext method but one field which is a text type keeps being imported as a numeric field which results in errors in the table created.

The procedure which will be automated will import the file on a regular basis and once the data is imported then the code deletes the source file.

The datafile Data08142010.csv has the current date in the name to ensure that the correct data is imported. Field16 or column "P" in the Excel file is the field causing the problem. Below is the code.

I then created an import specification to use with the DoCmd.Transfertext command in order to make sure that the correct field types were used but VBA would not recognize the import specification file. Here is the error message.

Run-time error '3625':
The text file specification 'Import-MainDataDtl_Data' does not exist.
You cannot import, export, or link using the specification.

From what I understand this is a problem with Access 2007. Apparently, Access 2007 VBA does not have the capability to recognize file specifications - at lest for comma delimited files.

Does anyone know of a work-around to deal with this problem? I guess that I will probably have to use another method but I am not sure which one to use.

1. File>get external data>import
2. select in the File of types box Text files (*.txt etc..
3. select the file
4. in the import text wizard window select delimited
5. Click advanced
6. in the import specification window
type the name of the field in the Field Name column
(here you can use the field names of the destination table, specify data type,
check the box Skip if you do not want to import the column)

7 click save as, give the specification a name <-- this is the specification name that you will use in the command line below

In Access 2007 there is no File > get external data> import process. The same procedure is created off of the ribbon commands.

1) Click on external data> text file which then opens another window called "Get external data - Text file"
2) Use radio button to select "Import the source data into a new table in the current database"
3) specify the source of the file using the browse procedure the clicjk OK
4) Choose radio button to select delimited format and then click next
5) this window allows you to choose delimiter and text qualifier and if first row contains names - click next
6) This window allows you to type the name of the field in the Field Name column, choose data type, and if you want field indexed - also can choose to skip field - then click next
7) This window allows you to add primary key or designate field as such - click next
8) In this window you specify table to import to - click finish
9) last window asks if you wish to save import steps - check box and fill in box with file specification name to save as "ImportSpecificationName" + add description - then you click save import

< last window asks if you wish to save import steps -> you saved the import steps not the import specification..

follow this

1) Click on external data> text file which then opens another window called "Get external data - Text file"
2) Use radio button to select "Import the source data into a new table in the current database"
3) specify the source of the file using the browse procedure the clicjk OK
4) Choose radio button to select delimited format and then click next
5) this window allows you to choose delimiter and text qualifier and if first row contains names - click next
6) This window allows you to type the name of the field in the Field Name column, choose data type, and if you want field indexed - also can choose to skip field - then click next
7) This window allows you to add primary key or designate field as such - click next

8) Click on ADVANCED button

9. in the import specification window
type the name of the field in the Field Name column
(here you can use the field names of the destination table, specify data type,
check the box Skip if you do not want to import the column)

10 click save as, give the specification a name <-- this is the specification name that you will use in the command line below

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

You know I saw the advanced tab and even clicked on it to check it out but somehow I didn't see the save Import Specification part. Oh well.....my bad.

You know its funny because I was looking up this method and in "Access 2007 VBA Bible" it states that... "Access 2007 VBA code doesn't recognize saved specifications..... only code that avoids using specifications will work". pg 310. I'm glad that they are mistaken.

Featured Post

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.

Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code.
This l…