Full Version: Count number of lines
UtterAccess Forums > Microsoft® Access > Access Date + Time
Is there a way of counting the number of lines
in a text file and then to abort a process if number
of lines exceed 1.
Such as
If CountLines(strFileName) > 1 then
MsgBox "Text"
xit or abort
Oalready have a variable declared for the filename
You would need to open the file programmatically and try to read it line by line. I do this to make sure a file contains records. Try this as a sample.
im lngFile as long
dim strFileName as string
dim strImportData as string
dim strEmptyFiles as string
strFileName =Some file name
lngFile = FreeFile
Open strFileName For Input As #lngFile
On Error Resume Next
Line Input #lngFile, strImportData
lngErr = Err.Number
On Error GoTo Err_comImportRateSim_Click
If lngErr = 62 Or lngErr = 130 Then
strEmptyFiles = strEmptyFiles & ";" & strFileName
End If
Close #lngFile
This could be modified easily to do exactly what you want. Hopefully it gives you the basics and you can get something from here. Don't be afraid to ask for more help if needed though.
Hi ken
Thanks for your quick reply.
I'am aware that I posted in the wrong area.
Should have been under code.
What are the numbers 62 and 130 ?
Should there not be and Else clause
Those numbers were the error numbers I used to see if the file was empty. You probably won't need that but I just gave you what I had. The idea is to open the file and build a counter and go from there for your needs. I didn't need an else but just go with what you need.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.