For example: ![TypeOfService] = getValue(strContent, 104, 105)
If there is no "104" in the file, it begins at beginning and copies all data to the end point of 105.
I hope I explained this clearly. I attempted on Line 41 but, I get a type mismatch.
Expand|Select|Wrap|Line Numbers
- Option Compare Database
- Option Explicit
- Public Function readFile(Optional strPath As String) As String
- 'Create a filesystemobject
- Dim fso As Object
- Set fso = CreateObject("scripting.filesystemobject")
- On Error GoTo Err_readFile
- 'Open file for reading
- strPath = "C:\Users\jeffrey.musgray\Desktop\TcossDocument.txt"
- readFile = fso.OpenTextFile(strPath, 1).ReadAll
- 'Cleanup
- Set fso = Nothing
- Exit Function
- Err_readFile:
- MsgBox "Error Description: " & Err.Description & vbCrLf & _
- "LastDll Error: " & Err.LastDllError & vbCrLf & _
- "Error Description: " & Err.Number & vbCrLf & _
- "Location: readFile"
- Public Sub InputFile(Optional strContent As String)
- Dim rsDao As DAO.Recordset
- Dim lngStart As Long
- On Error GoTo Err_InputFile
- Set rsDao = CurrentDb.OpenRecordset("SELECT * FROM TSR", dbOpenDynaset)
- rsDao.AddNew
- With rsDao
- ![TsrNumber] = getValue(strContent, 101, 103)
- If getValue(strContent, lngStart) Is Null Then NEXT
- ![TypeOfAction] = getValue(strContent, 103, 104)
- ![TypeOfService] = getValue(strContent, 104, 105)
- ![NetworkRequirement] = getValue(strContent, 105, 1061)
- ![OperationalSvcDate] = getValue(strContent, 1061, 1062)
- ![RequestedSvcDate] = getValue(strContent, 1062, 107)
- ![CCSDTrunkId] = getValue(strContent, 107, 108)
- ![PurposeUseCode] = getValue(strContent, 108, 110)
- ![TypeOperation] = getValue(strContent, 110, 111)
- ![ModulationBandwidth] = getValue(strContent, 111, 112)
- ![SVCAvailabilty] = getValue(strContent, 112, 115)
- ![SignalingMode] = getValue(strContent, 115, 116)
- ![CommSvcAuthorization] = getValue(strContent, 116, 117)
- ![ProgDesignatorCode] = getValue(strContent, 117, 118)
- ![OtimeExpeditingCharges] = getValue(strContent, 118, 119)
- ![TransmissionMediaAV] = getValue(strContent, 119, 1201)
- ![TerminalNodeLocation] = getValue(strContent, 1201, 1211)
- ![StateCountryCode] = getValue(strContent, 1211, 1221)
- ![AreaCode] = getValue(strContent, 1221, 1231)
- ![FacilityCode] = getValue(strContent, 1231, 1241)
- ![AddressSite] = getValue(strContent, 1241, 1251)
- ![RoomNumber] = getValue(strContent, 1251, 1271)
- ![TypeCryptoEquipment] = getValue(strContent, 1271, 1281)
- ![Interface] = getValue(strContent, 1281, 1301)
- ![UserTechnicalPOC] = getValue(strContent, 1301, 1311)
- ![MailAddress] = getValue(strContent, 1311, 1401)
- ![UnitIdentification] = getValue(strContent, 1401, 1202)
- ![TerminalNodeLocation2] = getValue(strContent, 1202, 1212)
- ![StateCountryCode2] = getValue(strContent, 1212, 1222)
- ![AreaCode2] = getValue(strContent, 1222, 1232)
- ![FacilityCode2] = getValue(strContent, 1232, 1242)
- ![AddressSite2] = getValue(strContent, 1242, 1252)
- ![RoomNumber2] = getValue(strContent, 1252, 1262)
- ![TerminalEquipment2] = getValue(strContent, 1262, 1272)
- ![TypeCryptoEquipment2] = getValue(strContent, 1272, 1282)
- ![Interface2] = getValue(strContent, 1282, 1302)
- ![UserTechnicalPoc2] = getValue(strContent, 1302, 1312)
- ![MailAddress2] = getValue(strContent, 1312, 1402)
- ![UnitIdentification2] = getValue(strContent, 1402, 401)
- ![NarrativeInformation] = getValue(strContent, 401, 402)
- ![TSRContact] = getValue(strContent, 402, 405)
- ![EquipSVCAcqDit] = getValue(strContent, 405, 4071)
- ![NationalSecSystem] = getValue(strContent, 4071, 409)
- ![CmoAcceptService] = getValue(strContent, 409, 411)
- ![SecurityRequirements] = getValue(strContent, 411, 413)
- ![ShippingInformation] = getValue(strContent, 413, 4151)
- ![DISAConNum] = getValue(strContent, 4151, 4152)
- ![ExerciseProjectName] = getValue(strContent, 4152, 416)
- ![CostThreshold] = getValue(strContent, 416, 417)
- ![Remarks] = getValue(strContent, 417, 421)
- ![USGateway] = getValue(strContent, 421, 430)
- ![EstimatedSvcLife] = getValue(strContent, 430, 4371)
- ![CPIWI] = getValue(strContent, 4371, 4372)
- ![CPIWM] = getValue(strContent, 4372, 501)
- ![JustifySVC] = getValue(strContent, 501, 510)
- ![FundingTcoApproval] = getValue(strContent, 510, 514)
- ![ReqActivityReqNumber] = getValue(strContent, 514)
- End With
- rsDao.Update
- Set rsDao = Nothing
- Exit Sub
- Err_InputFile:
- MsgBox "Error Description: " & Err.Description & vbCrLf & _
- "LastDll Error: " & Err.LastDllError & vbCrLf & _
- "Error Description: " & Err.Number & vbCrLf & _
- "Error Description: " & strContent & vbCrLf & _
- "Location: InputFile"
- End Sub
- Public Function getValue(strInput As String, lngStart As Long, Optional lngEnd As Long = 0) As String
- 'Get starting location
- Dim lngPosStart As Long
- Dim strStart As String
- Dim lngPosEnd As Long
- On Error GoTo Err_getValue
- strStart = vbCrLf & lngStart & "."
- lngPosStart = InStr(1, strInput, strStart) + Len(strStart)
- If lngEnd <> 0 Then
- lngPosEnd = InStr(1, strInput, vbCrLf & lngEnd & ".")
- Else
- lngPosEnd = Len(strInput)
- End If
- getValue = Mid(strInput, lngPosStart, lngPosEnd - lngPosStart)
- Exit Function
- Err_getValue:
- MsgBox "Error Description: " & Err.Description & vbCrLf & _
- "LastDll Error: " & Err.LastDllError & vbCrLf & _
- "Error Description: " & Err.Number & vbCrLf & _
- "Location: getValue"
- End Function