G
Guest
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?
file into a Memo field of a table?
Tony_VBACoder said: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?
Tony_VBACoder said: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