Ixtreme said:
I have a database that imports data from a csv file ( ~ separated).
The tables have all fields set to text.
What I want is to display a message after importing the files that
list the total number of records per table per field where the field
length contains more characters than is allowed.
Is there an easy way to achieve this?
Well, easy is a relative term. It's easy if you're an experienced VBA
programmer. Perhaps not so easy if you're not. Anyhow, here's an example ...
Public Function CountLongFields() As Long
Dim intFile As Integer
Dim strLine As String
Dim astrFields() As String
Dim iastrFields As Long
Dim strField As String
Dim lngCounter As Long
intFile = FreeFile
'open the text file
Open CurrentProject.Path & "\test.txt" For Input As #intFile
'loop until the end of the file
Do Until EOF(intFile)
'read each line of text from the file
Line Input #intFile, strLine
'split the line into fields
astrFields = Split(strLine, "~")
'check the length of each field
For iastrFields = LBound(astrFields) To UBound(astrFields)
strField = astrFields(iastrFields)
'if the length exceeds the max, increment a counter
If Len(strField) > 4 Then
lngCounter = lngCounter + 1
End If
Next iastrFields
Loop
'close the file
Close #intFile
'return the number of over-long fields
CountLongFields = lngCounter
End Function