Solved

Access 2010 Import all .txt files in Database directory

Posted on 2012-04-02
4
353 Views
Last Modified: 2012-04-02
I have a template database that I move to different directories based on which who’s data I need to process.  I need a button on my form that will find the location of the current database and import all .txt files located in the subdirectory “Import Files”.
0
Comment
Question by:JAMES125
  • 2
  • 2
4 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 37795694
private sub btn_click()

dim txtFile as string, strFolder as string
strFolder=currentproject.path & "\Import Files\"

txtFile=dir(strFolder & "*.txt")

while txtFile<>""
      debug.print strFolder & txtFile
     
      'place your codes your here to import the text files

      docmd.transfertext acimport,"import spec Name", "tableName", strfolder & txtFile,true



      txtFile=dir
wend

end sub


note: currentproject.path  'points to the folder where database is
0
 

Author Comment

by:JAMES125
ID: 37795872
I need a little more help.  Attached is an example of a file I will be importing.  Also I will be importing it into a table name "imports" with field names "Function" and "SSN".  The "2," is the function and the 9 digits that follow is the SSN "111111111".  Can you refine your code based on this information?
01.txt
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37795900
james125,

do you already have an "import specification" created for importing these files ?
0
 

Author Comment

by:JAMES125
ID: 37795911
I'm saving it now.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question