Import TXT file to database with distinct clause (1 Viewer)

jaryszek

Registered User.
Local time
Yesterday, 23:52
Joined
Aug 25, 2016
Messages
756
Hi,

i am using this command to load data from csv file:

Code:
DoCmd.TransferText transferType:=acImportDelim, TableName:="Temp_VolumeChanges", SpecificationName:="Temp_VolumeChanges", fileName:=selectFile, hasfieldnames:=True

It is possible to remove duplicated from the file in Access directly?

Best,
Jacek
 

CJ_London

Super Moderator
Staff member
Local time
Today, 07:52
Joined
Feb 19, 2013
Messages
16,607
to remove duplicates you need to import your file to a temporary table, then use a SELECT DISTINCT query to copy the rows to your main table

Alternatively you can use transfertext to link to your file and then use the SELECT DISTINCT query to copy to your main table

To automate further, once you have your linked table, you can copy over the same location as the original file to save creating more linked tables.

e.g. say your files are called

F1.txt
F2.txt

etc

copy the F1 file to a common location and rename it F.txt (use the filecopy command)
now create your linked table to the F.txt file
then run your SELECT DISTINCT query

for F2, all you then need to do is to copy F2 to the common location and rename to F.txt to overwrite the previous file, then run your query again
 

jaryszek

Registered User.
Local time
Yesterday, 23:52
Joined
Aug 25, 2016
Messages
756
hi CJ_london,

thank you very much. So i can link only once and only replacing txt files?

Best,
Jacek
 

CJ_London

Super Moderator
Staff member
Local time
Today, 07:52
Joined
Feb 19, 2013
Messages
16,607
that is correct - clearly the text files need to be the same in terms of number of columns, column headings etc.

Try it and see
 

Users who are viewing this thread

Top Bottom