
Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
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)