I imported a log file into access and am trying to parse out the data to a new table. I have been using the Instr and Mid function in a Query just fine. However, I could not get the second or third comma seperated field to get pulled so I created a function to do the job for me.
The problem is that although my declared variables have the correct data for pulling the fields I want (I tested the function by having it just return the variable value) it will not work together in the mid function.
The problem seems to be the intEnd value. If I just put in the value of "2" for example it works fine but it will not work with the intEnd in the formula.
I get a Run-time error 5: Invalid procedure call or argument
I have run out of ideas. Can anyone out there help me?
Here is the function:
Public Function SourcePort(ByVal strField As String) As String
Dim intFirst As Integer
Dim intSecond As Integer
Dim intEnd As Integer
intFirst = InStr(1, strField, ",") + 2
intSecond = InStr(intFirst, strField, ",")
intEnd = intSecond - intFirst
SourcePort = Mid(strField, intFirst, intSecond - intFirst)
End Function
The problem is that although my declared variables have the correct data for pulling the fields I want (I tested the function by having it just return the variable value) it will not work together in the mid function.
The problem seems to be the intEnd value. If I just put in the value of "2" for example it works fine but it will not work with the intEnd in the formula.
I get a Run-time error 5: Invalid procedure call or argument
I have run out of ideas. Can anyone out there help me?
Here is the function:
Public Function SourcePort(ByVal strField As String) As String
Dim intFirst As Integer
Dim intSecond As Integer
Dim intEnd As Integer
intFirst = InStr(1, strField, ",") + 2
intSecond = InStr(intFirst, strField, ",")
intEnd = intSecond - intFirst
SourcePort = Mid(strField, intFirst, intSecond - intFirst)
End Function