PC Review


Reply
Thread Tools Rate Thread

Add file name to table when importing several txt files using an-

 
 
dbguy11
Guest
Posts: n/a
 
      8th Apr 2010
I have several txt files that I import on a regular basis using an import
routine. But I have no way of identifying which file they came from if I have
to back track. I want to be able adjust my import routine so that it will
place the name of the file in a field the table its creating. Below is the
import routine I use.


Option Compare Database

Function btnImportAllA4s()
Dim strfile As String

ChDir ("D:\FTR\")
strfile = Dir("*.*")
Do While Len(strfile) > 0
DoCmd.SetWarnings False
DoCmd.TransferText acImportFixed, "FTR", _
"DLA_A4s", "D:\FTR\" & strfile, False
Kill "D:\FTR\" & strfile
strfile = Dir
Loop

End Function

Thank you in advance for assistance you can provide me.

--
dbguy11
 
Reply With Quote
 
 
 
 
Roger Carlson
Guest
Posts: n/a
 
      8th Apr 2010
Well, how about an executing an Update query immediately after the
TransferText statement.

CurrentDb.execute "UPDATE DLA_A4s SET FileName = '" & _
strfile & "' WHERE FileName IS NULL", dbFailOnError

This assumes you already have a field called FileName in the table and every
record will have a value except when a new file is imported.


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/...UBED1=ACCESS-L


"dbguy11" <(E-Mail Removed)> wrote in message
news:48BD817F-353B-4AA4-B6A6-(E-Mail Removed)...
>I have several txt files that I import on a regular basis using an import
> routine. But I have no way of identifying which file they came from if I
> have
> to back track. I want to be able adjust my import routine so that it will
> place the name of the file in a field the table its creating. Below is the
> import routine I use.
>
>
> Option Compare Database
>
> Function btnImportAllA4s()
> Dim strfile As String
>
> ChDir ("D:\FTR\")
> strfile = Dir("*.*")
> Do While Len(strfile) > 0
> DoCmd.SetWarnings False
> DoCmd.TransferText acImportFixed, "FTR", _
> "DLA_A4s", "D:\FTR\" & strfile, False
> Kill "D:\FTR\" & strfile
> strfile = Dir
> Loop
>
> End Function
>
> Thank you in advance for assistance you can provide me.
>
> --
> dbguy11



 
Reply With Quote
 
dbguy11
Guest
Posts: n/a
 
      8th Apr 2010
Thank you very much it works great! I will be using this on several of my dbs
its going to come in very handy.
--
dbguy11


"Roger Carlson" wrote:

> Well, how about an executing an Update query immediately after the
> TransferText statement.
>
> CurrentDb.execute "UPDATE DLA_A4s SET FileName = '" & _
> strfile & "' WHERE FileName IS NULL", dbFailOnError
>
> This assumes you already have a field called FileName in the table and every
> record will have a value except when a new file is imported.
>
>
> --
> --Roger Carlson
> MS Access MVP
> Access Database Samples: www.rogersaccesslibrary.com
> Want answers to your Access questions in your Email?
> Free subscription:
> http://peach.ease.lsoft.com/scripts/...UBED1=ACCESS-L
>
>
> "dbguy11" <(E-Mail Removed)> wrote in message
> news:48BD817F-353B-4AA4-B6A6-(E-Mail Removed)...
> >I have several txt files that I import on a regular basis using an import
> > routine. But I have no way of identifying which file they came from if I
> > have
> > to back track. I want to be able adjust my import routine so that it will
> > place the name of the file in a field the table its creating. Below is the
> > import routine I use.
> >
> >
> > Option Compare Database
> >
> > Function btnImportAllA4s()
> > Dim strfile As String
> >
> > ChDir ("D:\FTR\")
> > strfile = Dir("*.*")
> > Do While Len(strfile) > 0
> > DoCmd.SetWarnings False
> > DoCmd.TransferText acImportFixed, "FTR", _
> > "DLA_A4s", "D:\FTR\" & strfile, False
> > Kill "D:\FTR\" & strfile
> > strfile = Dir
> > Loop
> >
> > End Function
> >
> > Thank you in advance for assistance you can provide me.
> >
> > --
> > dbguy11

>
>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help please : importing many .txt files in a folder to one table mhmaid Microsoft Access External Data 23 2nd Jul 2009 09:13 PM
importing a linked table from one file to another as a local table Laoballer Microsoft Access 3 26th Mar 2009 07:41 PM
Importing text files into a table =?Utf-8?B?U3RlcGhlbiBFbmdsaXNo?= Microsoft Access VBA Modules 3 27th Oct 2006 05:18 AM
Importing all .txt files in folder into table =?Utf-8?B?VEVCMg==?= Microsoft Access VBA Modules 3 9th Nov 2005 05:31 PM
Importing multiple .CSV files into a Table jasperwt Microsoft Access Database Table Design 1 25th May 2005 12:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:43 PM.