-----Original Message-----
Hi Steve,
The FileContents() function below reads the contents of a textfile into
a variable in VBA. If your text files aren't too big (a few hundred
kilobytes shouldn't be a problem) just paste it into a module in your
database. Then use something like this air code:
Dim strFileSpec As String
Dim strTarget As String
strFileSpec = "D:\Folder\test.txt"
strTarget = "THISISATEST"
If InStr(FileContents(strFileSpec), strTarget) > 0 Then
'Do something
Else
'Do something else
End If
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
Hello,
Can I make access check the contents of a text file?
If I have a text file, say, test.txt. Can I have Access
2003 check to see that it contains "THISISATEST"?
Then, if it DOES contain it, do one thing, and if it
DOESN'T do another?
It would be best if it will only report an EXACT match
(for e.g. the text file ONLY contains the specified
words), but any way is better than no way!!!
Thanks!
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.
.