PC Review


Reply
Thread Tools Rate Thread

Importing text files in their entirety into memo fields

 
 
Dan Quill
Guest
Posts: n/a
 
      10th Oct 2004
I've read through a dozen different ideas on how to attack importing
straight text files into a memo field without breaking it up in dozens
of records. Basically, I have a few thousand text files to import
into a database (I know it will grow large) so search and replace
doesn't work.

Any help on this would be greatly appreciated, this is one of the few
problems I've found that I couldn't answer by just searching deja.
 
Reply With Quote
 
 
 
 
John Nurick
Guest
Posts: n/a
 
      10th Oct 2004
Hi Dan,

The function below takes the filespec of a textfile and returns its
contents. So if you have a table with one field containing the names or
filespecs and a memo field ready for the contents, you can simply use a
query to update the memo field to
FileContents([XXX])
where XXX is the name of the filespec field.

The FileContents function is intended for small-to-medium text files
only and I've never tested it with a file bigger than 4 megabytes,
though I expect it will work with much larger ones.


On 9 Oct 2004 21:58:36 -0700, (E-Mail Removed) (Dan Quill)
wrote:

>I've read through a dozen different ideas on how to attack importing
>straight text files into a memo field without breaking it up in dozens
>of records. Basically, I have a few thousand text files to import
>into a database (I know it will grow large) so search and replace
>doesn't work.
>
>Any help on this would be greatly appreciated, this is one of the few
>problems I've found that I couldn't answer by just searching deja.



Public Function FileContents( _
ByVal FileSpec As Variant, _
Optional ByVal ReturnErrors As Boolean = False, _
Optional ByRef ErrCode As Long) As Variant
'Retrieves contents of file as a string
'Silently returns Null on error unless
' ReturnErrors is true, in which case
' uses CVErr() to return a error value.
' Alternatively, you can retrieve the error
' code in the ErrCode argument

Dim lngFN As Long

On Error GoTo Err_FileContents
If IsNull(FileSpec) Then
FileContents = Null
Else
lngFN = FreeFile()
Open FileSpec For Input As #lngFN
FileContents = Input(LOF(lngFN), #lngFN)
End If
ErrCode = 0
GoTo Exit_FileContents

Err_FileContents:
ErrCode = Err.Number
If ReturnErrors Then
FileContents = CVErr(Err.Number)
Else
FileContents = Null
End If
Err.Clear
Exit_FileContents:
Close #lngFN
End Function

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Memo Field - Append Text fields into memo field??? =?Utf-8?B?UGF0IFN0ZXdhcnQ=?= Microsoft Access 1 18th Feb 2007 09:45 PM
Re: Using GROUP BY in query expression on MEMO fields it truncates data in MEMO fields to first 255 characters Douglas J. Steele Microsoft Access Queries 4 7th Dec 2004 07:29 PM
Re: Using GROUP BY in query expression on MEMO fields it truncates data in MEMO fields to first 255 characters Douglas J. Steele Microsoft Access 4 7th Dec 2004 07:29 PM
Re: Using GROUP BY in query expression on MEMO fields it truncates data in MEMO fields to first 255 characters Douglas J. Steele Microsoft Access Reports 4 7th Dec 2004 07:29 PM
Importing text with linebreaks into memo fields RSGinCA Microsoft Access External Data 4 12th Jan 2004 07:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:12 PM.