Solved

Access 2010 Import all .txt files in Database directory

Posted on 2012-04-02
4
357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

615 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