ok i checked for the text file in form view and there was nothing there
either. So i deleted the FileContents module then recreated it with the
Immediate view and when i typed in the ?FileContents... with a real file name
it came up Null. i opened that file in notepad to confirm that there was a
text document there.
If you type this into the Immediate pane, substituting the path to a
real textfile on your system. Remember that you must include the "txt"
extension:
? FileContents("D:\Folder\Other Folder\Filename.txt")
and the result is
Null
then this needs to be sorted out or there's no chance of the update
query working.
First, check that you've typed the path accurately. Copy it to the
clipboard - including the quote marks. Then go to the Windows Start
menu, select Run..., and paste the path into the Open: field and hit OK.
The file should open in Notepad or another text editor. If not, then
you've probably mistyped the path.
Having confirmed that you've got the file name and path correct, the
next thing is to check the way the FileContents() code is executing.
1 Back in the VB editor, set a breakpoint at the beginning of the
function by clicking in the left margin of the code pane next to
Public Function
2 Then open the Debug toolbar.
3 In the Immediate Pane, click on the
? FileContents("D:\Folder\Other Folder\Filename.txt")
and hit Enter.
4 Use the Step Into button on the Debug toolbar to step through the code
line by line, following the successively highlighted lines of code to
observe the execution path. If the highlight gets to this part of the
code
Err_FileContents:
ErrCode = Err.Number
If ReturnErrors Then
stop, go to the Immediate Pane, and type
? Err.Number, Err.Description
hit Enter, and post back here with the results.
Here is the copy of the update query you asked for.
FileContents("c:\sixmonth_data\text_files\" & [DocName])
i'm sorry i'm not understanding what's going on, but i really appreaciate
your help.
Thanks
Dwight
John Nurick said:
Hi Dwight,
The function below will read and return the contents of a textfile, and
can be used in an Access query. Paste it into a module in your database
(making sure the module is not named "FileContents").
Make a copy of your database to be on the safe side. Add a memo field to
the table - I'll call it fldMemo - and then create an update query on
the table to update fldMemo. The "Update To" cell will look something
like this:
FileContents("D:\Folder\" & [XXX])
replacing D:\Folder\ with the actual location of your files and XXX with
the name of the field that contains the filenames. If the field contains
the filespecs and not just the names all you need is
FileContents([XXX]).
Public Function FileContents(FileSpec As Variant, _
Optional 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 an error value.
' Optionally, 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
On Tue, 5 Oct 2004 12:39:04 -0700, Dwight
i have an Access XP database that contains a field with a text document name.
i need to add a memo field with that text document, keeping the format of the
document.
once i learn how to import this text document into my data field i will need
to create a macro or some automation for this process since i have over 34
thousand records i need to import the coresponding text documents
thanks