Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / March 2007

Tip: Looking for answers? Try searching our database.

ACC 2000: VBA Import Text Files into Memo field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tony_VBACoder - 15 Mar 2007 16:21 GMT
With Access 2000, is there a way to use VBA to import the contents of a Text
file into a Memo field of a table?
Dirk Goldgar - 15 Mar 2007 16:49 GMT
> With Access 2000, is there a way to use VBA to import the contents of
> a Text file into a Memo field of a table?

It's easy enough to do using a bound text box on a form.  For example:

'----- start of example code -----
   Dim strFileName As String
   Dim intFileNo As Integer

   strFileName = Me.txtFilePath   ' full path to file

   intFileNo = FreeFile()
   Open strFileName For Input As #intFileNo
   Me.txtFileData = Input(LOF(intFileNo), intFileNo)
   Close #intFileNo

'----- end of example code -----

Note that the example code doesn't check the size of the file to make
sure it's not too big to save.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Tony_VBACoder - 15 Mar 2007 19:45 GMT
I actually accomplished this using the FileSystem Object along with a
recordset object to put the text file's contents into the table.  My sample
code is below:

Dim streamCurrent As TextStream
Dim fso As FileSystemObject
Dim objFolder As Folder
Dim objTextFilesIncoming As Files
Dim objTextFile As File
Dim rst As DAO.Recordset

Dim sPathText As String
sPathText = "C:\TEMP\VBAPDFTester\Export Text"
Set rst = CurrentDb.OpenRecordset("Table1")

' Loop through the Text files to insert the data into the Table
For Each objTextFile In objTextFilesIncoming
   ' Open the file as a stream object
   Set streamCurrent = objTextFile.OpenAsTextStream(ForReading,
TristateUseDefault)
   ' Insert the Data from the Text File.  Use a Recordset so that quotes
get inserted properly.
   rst.AddNew
   rst!FullText = streamCurrent.ReadAll
   rst.Update
   
   ' Close the Text Stream object so we can delete the file after we
inserted the text into the database
   streamCurrent.Close
   Set streamCurrent = Nothing
   
   'objTextFile.Copy sProcessedFileName
   'objTextFile.Delete True
Next

> > With Access 2000, is there a way to use VBA to import the contents of
> > a Text file into a Memo field of a table?
[quoted text clipped - 16 lines]
> Note that the example code doesn't check the size of the file to make
> sure it's not too big to save.
Dirk Goldgar - 15 Mar 2007 20:23 GMT
> I actually accomplished this using the FileSystem Object along with a
> recordset object to put the text file's contents into the table.  My
[quoted text clipped - 30 lines]
>    'objTextFile.Delete True
> Next

Yes, that's a perfectly valid way of doing it.  If I'd known exactly
what you had in mind, I'd have written similar code.  I would use the
simple VB I/O statements I posted, in preference to the scripting
objects, in the interest of simple efficiency and
reference-independence, but it's no big deal.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.