Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 6th, 2004, 09:21 AM
Authorized User
 
Join Date: Oct 2003
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. :)
 
Old June 30th, 2013, 07:02 PM
Registered User
 
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

Code:
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
Next
Next
GoTo CleanUp
ErrHandler:
MsgBox Err.Description Resume CleanUp Resume 'debugging only
CleanUp:
MsgBox "done."
End Sub

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





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 08: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.