S
Steve Roberts
I have a text file that I need to import into a table. I have it working
fine except that I get an error 13 type mismatch error on the last line of
each of my text files. The rest of the lines in the text file seem to import
just fine. I assume it is because of how I am looping through the lines in
the text file but I can't seem to figure out where the problem is.
The code I am using is below.
Thanks in advance for your suggestions.
Steve
Sub ReadTextFile(strFile As String)
Dim intF As Integer
Dim I As Integer
Dim lngLines As Long
Dim lngBlank As Long
Dim arrLineParts() As String
Dim arrFixedFeatures() As String
Dim Color, ComputerName, Copies, Duplex, MediaType, strDate, strTime,
SquareFT, Username, DocumentName, PrinterName, ClientCode As String
Dim SubCode, PaperSize, Features, PageCount, Cost, AccountBalance, Sets,
Originals, strLineBuf As String
intF = FreeFile()
Open strFile For Input As #intF
Do While EOF(intF) = False
Line Input #intF, strLineBuf
arrLineParts = Split(strLineBuf, ",")
arrLineParts(9) = Replace(arrLineParts(9), "/", ",")
arrFixedFeatures = Split(arrLineParts(9), ",")
Username = Replace(arrLineParts(0), "MARTIN\", "")
DocumentName = arrLineParts(1)
PrinterName = Replace(arrLineParts(2), "\\PRINTSVR\", "")
strDate = arrLineParts(3)
strTime = arrLineParts(4)
ComputerName = arrLineParts(5)
ClientCode = arrLineParts(6)
SubCode = arrLineParts(7)
PaperSize = arrLineParts(8)
Features = arrLineParts(9)
PageCount = arrLineParts(11)
Cost = arrLineParts(12)
AccountBalance = arrLineParts(13)
For I = 1 To UBound(arrFixedFeatures())
If (arrFixedFeatures(I) = "C") Then Color = "Y"
If arrFixedFeatures(I) = "D" Then Duplex = "Y"
If Left(arrFixedFeatures(I), 3) = "CP=" Then Sets =
Replace(arrFixedFeatures(I), "CP=", "")
If Left(arrFixedFeatures(I), 3) = "MT=" Then MediaType =
Replace(arrFixedFeatures(I), "MT=", "")
Next
Originals = (PageCount / Sets)
Copies = (PageCount - Originals)
If PrinterName = "Xerox510" Or PrinterName = "Xerox8830" Then
SquareFT = Left(PaperSize, 5) * Right(PaperSize, 5)
SquareFT = SquareFT / 144
Else
SquareFT = ""
End If
Select Case MediaType
Case Is = "Paper"
MediaType = "Bond"
Case Is = "Plain"
MediaType = "Bond"
Case Is = "PLAINORRECYCLED"
MediaType = "Bond"
Case Is = ""
MediaType = "Bond"
Case Is = "Film"
MediaType = "Mylar"
End Select
DoCmd.RunSQL ("INSERT INTO PCOUNTER_Logs(UserName, DocumentName,
PrinterName, dtDate, dtTime, ComputerName, ClientCode, PaperSize, Features,
PageCount, Cost, Color, Duplex, Originals, Sets, Copies, MediaType,SquareFt)
" _
& " VALUES('" & Username & "','" & DocumentName &
"','" & PrinterName & "','" & strDate & "','" & strTime & "','" &
ComputerName & "','" & ClientCode & "','" & PaperSize & "','" & Features &
"','" & PageCount & "','" & Cost & "" _
& "','" & Color & "','" & Duplex & "','" & Originals &
"','" & Sets & "','" & Copies & "','" & MediaType & "','" & SquareFT & "')")
Color = ""
Duplex = ""
Originals = ""
Copies = ""
MediaType = ""
Loop
End Sub
fine except that I get an error 13 type mismatch error on the last line of
each of my text files. The rest of the lines in the text file seem to import
just fine. I assume it is because of how I am looping through the lines in
the text file but I can't seem to figure out where the problem is.
The code I am using is below.
Thanks in advance for your suggestions.
Steve
Sub ReadTextFile(strFile As String)
Dim intF As Integer
Dim I As Integer
Dim lngLines As Long
Dim lngBlank As Long
Dim arrLineParts() As String
Dim arrFixedFeatures() As String
Dim Color, ComputerName, Copies, Duplex, MediaType, strDate, strTime,
SquareFT, Username, DocumentName, PrinterName, ClientCode As String
Dim SubCode, PaperSize, Features, PageCount, Cost, AccountBalance, Sets,
Originals, strLineBuf As String
intF = FreeFile()
Open strFile For Input As #intF
Do While EOF(intF) = False
Line Input #intF, strLineBuf
arrLineParts = Split(strLineBuf, ",")
arrLineParts(9) = Replace(arrLineParts(9), "/", ",")
arrFixedFeatures = Split(arrLineParts(9), ",")
Username = Replace(arrLineParts(0), "MARTIN\", "")
DocumentName = arrLineParts(1)
PrinterName = Replace(arrLineParts(2), "\\PRINTSVR\", "")
strDate = arrLineParts(3)
strTime = arrLineParts(4)
ComputerName = arrLineParts(5)
ClientCode = arrLineParts(6)
SubCode = arrLineParts(7)
PaperSize = arrLineParts(8)
Features = arrLineParts(9)
PageCount = arrLineParts(11)
Cost = arrLineParts(12)
AccountBalance = arrLineParts(13)
For I = 1 To UBound(arrFixedFeatures())
If (arrFixedFeatures(I) = "C") Then Color = "Y"
If arrFixedFeatures(I) = "D" Then Duplex = "Y"
If Left(arrFixedFeatures(I), 3) = "CP=" Then Sets =
Replace(arrFixedFeatures(I), "CP=", "")
If Left(arrFixedFeatures(I), 3) = "MT=" Then MediaType =
Replace(arrFixedFeatures(I), "MT=", "")
Next
Originals = (PageCount / Sets)
Copies = (PageCount - Originals)
If PrinterName = "Xerox510" Or PrinterName = "Xerox8830" Then
SquareFT = Left(PaperSize, 5) * Right(PaperSize, 5)
SquareFT = SquareFT / 144
Else
SquareFT = ""
End If
Select Case MediaType
Case Is = "Paper"
MediaType = "Bond"
Case Is = "Plain"
MediaType = "Bond"
Case Is = "PLAINORRECYCLED"
MediaType = "Bond"
Case Is = ""
MediaType = "Bond"
Case Is = "Film"
MediaType = "Mylar"
End Select
DoCmd.RunSQL ("INSERT INTO PCOUNTER_Logs(UserName, DocumentName,
PrinterName, dtDate, dtTime, ComputerName, ClientCode, PaperSize, Features,
PageCount, Cost, Color, Duplex, Originals, Sets, Copies, MediaType,SquareFt)
" _
& " VALUES('" & Username & "','" & DocumentName &
"','" & PrinterName & "','" & strDate & "','" & strTime & "','" &
ComputerName & "','" & ClientCode & "','" & PaperSize & "','" & Features &
"','" & PageCount & "','" & Cost & "" _
& "','" & Color & "','" & Duplex & "','" & Originals &
"','" & Sets & "','" & Copies & "','" & MediaType & "','" & SquareFT & "')")
Color = ""
Duplex = ""
Originals = ""
Copies = ""
MediaType = ""
Loop
End Sub