Hi - I need help with VBA reading an external .txt file. When I read the 1st record I get accurate data but when I read the next record I get 2 extra bytes and for the 3rd record it adds on another 2 bytes (i.e 4 bytes total) look at example:
External .txt file:
DbservNM \\servernm\one
McrServNM \\servernm\two
RptServNM \\servernm\three
Code in VBA:
Private Type ServerRowRec
strServerName As String * 12
strPathName As String * 16
End Type
Function GetDBPath(strDirectDB As String, strDirectMacroDB As String, strDirectRPTDB As String)
Dim strDirectory As String
Dim srtReportDB As String
Dim strMacroDB As String
Dim strRowRec As ServerRowRec
Dim strServerPath As String
Dim intRow As Integer
Dim intRecNum As Integer
Dim strColA As String
intRecNum = 1
strServerPath = "Z:\program Files\sqllib\RMPCommFile.txt"
Open strServerPath For Random As #1 Len = Len(strRowRec)
Do Until intRecNum > 3
Get #1, intRecNum, strRowRec
If strRowRec.strServerName = "DbServNM " Then
strDirectDB = strRowRec.strPathName
ElseIf strRowRec.strServerName = "McrServNM " Then
strDirectMacroDB = strRowRec.strPathName
ElseIf strRowRec.strServerName = "RptServNM " Then
srtReportDB = strRowRec.strPathName
End If
intRecNum = intRecNum + 1
Loop
Close #1
End Function
Results as shown when the cursor is placed over the field:
strRowRec.strServerName="DBServNM "
strRowRec.strServerName " McrServNM " ------> (the space appears as squares prior to McrServNM)
strRowRec.strServerName "ee RptServNM"
PLEASE HELP !
External .txt file:
DbservNM \\servernm\one
McrServNM \\servernm\two
RptServNM \\servernm\three
Code in VBA:
Private Type ServerRowRec
strServerName As String * 12
strPathName As String * 16
End Type
Function GetDBPath(strDirectDB As String, strDirectMacroDB As String, strDirectRPTDB As String)
Dim strDirectory As String
Dim srtReportDB As String
Dim strMacroDB As String
Dim strRowRec As ServerRowRec
Dim strServerPath As String
Dim intRow As Integer
Dim intRecNum As Integer
Dim strColA As String
intRecNum = 1
strServerPath = "Z:\program Files\sqllib\RMPCommFile.txt"
Open strServerPath For Random As #1 Len = Len(strRowRec)
Do Until intRecNum > 3
Get #1, intRecNum, strRowRec
If strRowRec.strServerName = "DbServNM " Then
strDirectDB = strRowRec.strPathName
ElseIf strRowRec.strServerName = "McrServNM " Then
strDirectMacroDB = strRowRec.strPathName
ElseIf strRowRec.strServerName = "RptServNM " Then
srtReportDB = strRowRec.strPathName
End If
intRecNum = intRecNum + 1
Loop
Close #1
End Function
Results as shown when the cursor is placed over the field:
strRowRec.strServerName="DBServNM "
strRowRec.strServerName " McrServNM " ------> (the space appears as squares prior to McrServNM)
strRowRec.strServerName "ee RptServNM"
PLEASE HELP !