Solved

Access 2010 Import all .txt files in Database directory

Posted on 2012-04-02
4
351 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 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
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 119

Expert Comment

by:Rey Obrero
Comment Utility
james125,

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

Author Comment

by:JAMES125
Comment Utility
I'm saving it now.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now