Importing from text file questions

kirkm76

New member
Local time
Today, 14:17
Joined
Sep 6, 2007
Messages
1
OK, I have a database that imports data from a comma-seperated text file. Previously the db was deployed at one site so I just selected the fields to import in the import specification. However the db is now going to go out to other sites. My problem is the file I import from has the fields in different places at the other sites. There are 4 fields I actually grab. 2 of them are in a standard position, so no issue there. But the other 2 I would need to somehow test and see if they are the right field and then import them to a table. Any Ideas on how to go about this?
 
Now, I'm not quite sure this would work, but I'm having a similar issue that I've seemed to solve for my particular problem.
Note: Please someone correct me if I'm wrong.

The solution I've found is in two steps:
1) I link/import said csv file as a temp table that'll soon be deleted.
2) Execute an sql command using the "INSERT INTO" function. Well, if the csv file has headers and was linked accordingly by setting the header boolean to true, then the SQL command will know what fields are in the table. Make sure you line up the fields correctly using commas.
3) Delete temp table (if necessary)
Example:
In this Field is the field,# is the field number in that particular table (Which in the temp table it can be anywhere), M stands for Master and T stands for Temp
Code:
Step 1:
     DoCmd.TransferText acLinkDelim, "", TempTable,CSVFilename, True 'the header function option

Step 2:

    Dim SQL As String
    
    SQL = "INSERT INTO Master_Test_Table (Field1M, Field2M,Field3M, Field4M, Field5M)" _
    & " SELECT Field3T, Field1T, Field2T, Field5T, Field4T" _
    & " FROM TempTable;"
    

    CurrentDb.Execute SQL

Step 3:
    DoCmd.DeleteObject acTable, TempTable
 

Users who are viewing this thread

Back
Top Bottom