Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SEARCH FOR STRING ON A TEXT FILE 1

Status
Not open for further replies.

villica

Programmer
Feb 25, 2000
332
CA
Hi everyone. is it possible to search for a string on text file before it gets imported to access.

The string is "no data to print'.
If found I don't want to import the file.

Any ideas, suggestions

villica
 
villica,
I can't tell you why, but I'm not a big fan of the [tt]FileSystemObject[/tt] recomended by [navy]PHV[/navy] so here is an alternative:
Code:
Function DataInFile(FileName As String) As Boolean
Dim intFile As Integer
Dim strLine As String
intFile = FreeFile
Open FileName For Input As #intFile
Do
  Line Input #intFile, strLine
  If InStr(strLine, "no data to print") <> 0 Then
    DataInFile = True
    Exit Do
  End If
Loop Until EOF(intFile)
Close #intFile
End Function

In your code you can use it in an [tt]If..Then[/tt] statement to determine if the [tt]FileName[/tt] needs to be imported.

Hope this helps,
CMP

(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top