Solved

Access 2010 Import all .txt files in Database directory

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

679 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