Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old October 6th, 2004, 09:21 AM
Authorized User
Join Date: Oct 2003
Location: Cleveland, OH, USA.
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default Link a text file to Access using VBA

Does anyone know how to link a text file to an Access
database using VBA code? I've tried variations of
the DoCmd.TransferDatabase using a TransferType of
acLink, but it seems that there is no option under
the DatabaseType.

I have been able to link the text file using File |
Get External Data | Link, but have had no luck at
all trying to do this using VBA.

I know that linking a text file or Excel spreadsheet
may be considered more of an exception in many
respects, but any ideas would be GREATLY appreciated!

Thank you. :)
Reply With Quote
  #2 (permalink)  
Old June 30th, 2013, 07:02 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Link Text File to MS Access 2010 as a table

Sub LinkToTextFiles()
On Error GoTo ErrHandler
' include a reference to the "Microsoft Scripting Runtime"
Dim objFSO As FileSystemObject 
Dim objDirRoot As Folder
Dim objDir As Folder
Dim objFile As File
Dim PageName As String
Set objFSO = New FileSystemObject Set objDirRoot = objFSO.GetFolder("C:\MonthlyReports") For Each objDir In objDirRoot.SubFolders
Debug.Print objDir.Name
For Each objFile In objDir.Files
If objFile.Name Like "*.txt" Then
PageName = objFile.Name ' create link specification by manually importing one sample ' use the advanced... button to save a particular import style ' the link specification is optional if you want VBA to guess about columns ' in your text file DoCmd.TransferText acImportFixed, "MOR_Link_Specification", _
PageName, _ objFile.Path, _ False
Debug.Print PageName
Else ' if no txt file is picked then try another one End If
GoTo CleanUp
MsgBox Err.Description Resume CleanUp Resume 'debugging only
MsgBox "done."
End Sub

Last edited by sefarkas; June 30th, 2013 at 07:05 PM. Reason: try to make the indenting show up correctly
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
In Rails how to link to text file humphrys Ruby 1 October 16th, 2007 09:22 AM
Access VBA - Controlling Text boxes in a form Scripts82 Access VBA 4 February 8th, 2006 07:35 PM
Text File-Newbie VBA Access mbeirn Access VBA 1 October 6th, 2005 07:18 AM
VBA access List data to text file Data-Base Access VBA 6 September 15th, 2005 04:04 PM
import data from text file to excel(VBA) topr Excel VBA 2 August 26th, 2004 11:36 PM

All times are GMT -4. The time now is 06:58 AM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.