Solved

Access 2010 Import all .txt files in Database directory

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

752 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