Dim oEdiDoc As Fredi.ediDocument Dim oSchema As Fredi.ediSchema Dim oSchemas As Fredi.ediSchemas Dim oSegment As Fredi.ediDataSegment Dim sSegmentID As String Dim sLoopID As String Dim nArea As Integer Dim sValue As String 'CREATES EDIDOC OBJECT Set oEdiDoc = New Fredi.ediDocument 'THIS MAKES CERTAIN THAT FREDI ONLY USES THE SEF FILE PROVIDED, AND THAT IT DOES 'NOT USE ITS BUILT-IN STANDARD REFERENCE TABLE TO TRANSLATE THE EDI FILE. Set oSchemas = oEdiDoc.GetSchemas oSchemas.EnableStandardReference = False 'THIS OPTIONS STOPS FREDI FROM KEEPING ALL THE SEGMENTS IN MEMORY oEdiDoc.CursorType = Cursor_ForwardOnly 'LOADS THE SEF FILE Set oSchema = oEdiDoc.LoadSchema("810_X12-4010.SEF.TXT", 0) 'LOADS THE EDI FILE oEdiDoc.LoadEdi "810_X12-4010.TXT" 'GETS THE FIRST DATA SEGMENT Set oSegment = oEdiDoc.FirstDataSegment 'LOOP THAT WILL TRAVERSE THRU EDI FILE FROM TOP TO BOTTOM Do While Not oSegment Is Nothing 'DATA SEGMENTS WILL BE IDENTIFIED BY THEIR ID, THE LOOP SECTION AND AREA '(OR TABLE) NUMBER THAT THEY ARE IN. sSegmentID = oSegment.ID sLoopID = oSegment.LoopSection nArea = oSegment.Area If nArea = 0 then If sLoopId = "" then If sSegmentId = "ISA" then sValue = oSegment.DataElementValue(1) 'Authorization Information Qualifier sValue = oSegment.DataElementValue(2) 'Authorization Information sValue = oSegment.DataElementValue(3) 'Security Information Qualifier sValue = oSegment.DataElementValue(4) 'Security Information sValue = oSegment.DataElementValue(5) 'Interchange ID Qualifier sValue = oSegment.DataElementValue(6) 'Interchange Sender ID sValue = oSegment.DataElementValue(7) 'Interchange ID Qualifier sValue = oSegment.DataElementValue(8) 'Interchange Receiver ID sValue = oSegment.DataElementValue(9) 'Interchange Date sValue = oSegment.DataElementValue(10) 'Interchange Time sValue = oSegment.DataElementValue(11) 'Interchange Control Standards Identifier sValue = oSegment.DataElementValue(12) 'Interchange Control Version Number sValue = oSegment.DataElementValue(13) 'Interchange Control Number sValue = oSegment.DataElementValue(14) 'Acknowledgment Requested sValue = oSegment.DataElementValue(15) 'Usage Indicator sValue = oSegment.DataElementValue(16) 'Component Element Separator ElseIf sSegmentId = "GS" then sValue = oSegment.DataElementValue(1) 'Functional Identifier Code sValue = oSegment.DataElementValue(2) 'Application Sender's Code sValue = oSegment.DataElementValue(3) 'Application Receiver's Code sValue = oSegment.DataElementValue(4) 'Date sValue = oSegment.DataElementValue(5) 'Time sValue = oSegment.DataElementValue(6) 'Group Control Number sValue = oSegment.DataElementValue(7) 'Responsible Agency Code sValue = oSegment.DataElementValue(8) 'Version / Release / Industry Identifier Code End If 'sSegmentID End If 'sLoopID ElseIf nArea = 1 then If sLoopId = "" then If sSegmentId = "ST" then sValue = oSegment.DataElementValue(1) 'Transaction Set Identifier Code sValue = oSegment.DataElementValue(2) 'Transaction Set Control Number ElseIf sSegmentId = "BIG" then sValue = oSegment.DataElementValue(1) 'Date sValue = oSegment.DataElementValue(2) 'Invoice Number sValue = oSegment.DataElementValue(3) 'Date sValue = oSegment.DataElementValue(4) 'Purchase Order Number End If 'Segment ID ElseIf sLoopId = "N1" then 'If loop has more that one instance, then you should check for the qualifier that differentiates the loop instances here e.g. 'If sSegmentID = "N1" then ' sLoopQlfr = oSegment.DataElementValue(1) 'In most cases the loop qualifier is the first element of the first segment in the loop, but not necessarily 'End If 'If sLoopQlfr = "QualifierValue" then If sSegmentId = "N1" then sValue = oSegment.DataElementValue(1) 'Entity Identifier Code sValue = oSegment.DataElementValue(2) 'Name sValue = oSegment.DataElementValue(3) 'Identification Code Qualifier sValue = oSegment.DataElementValue(4) 'Identification Code ElseIf sSegmentId = "N3" then sValue = oSegment.DataElementValue(1) 'Address Information ElseIf sSegmentId = "N4" then sValue = oSegment.DataElementValue(1) 'City Name sValue = oSegment.DataElementValue(2) 'State or Province Code sValue = oSegment.DataElementValue(3) 'Postal Code End If 'sSegmentID End If 'sLoopID ElseIf nArea = 2 then If sLoopId = "IT1" then If sSegmentId = "IT1" then sValue = oSegment.DataElementValue(1) 'Assigned Identification sValue = oSegment.DataElementValue(2) 'Quantity Invoiced sValue = oSegment.DataElementValue(3) 'Unit or Basis for Measurement Code sValue = oSegment.DataElementValue(4) 'Unit Price sValue = oSegment.DataElementValue(5) 'Basis of Unit Price Code sValue = oSegment.DataElementValue(6) 'Product/Service ID Qualifier sValue = oSegment.DataElementValue(7) 'Product/Service ID End If 'Segment ID ElseIf sLoopId = "IT1;PID" then If sSegmentId = "PID" then sValue = oSegment.DataElementValue(1) 'Item Description Type sValue = oSegment.DataElementValue(2) 'Product/Process Characteristic Code sValue = oSegment.DataElementValue(3) 'Agency Qualifier Code sValue = oSegment.DataElementValue(4) 'Product Description Code sValue = oSegment.DataElementValue(5) 'Description End If 'sSegmentID End If 'sLoopID ElseIf nArea = 3 then If sLoopId = "" then If sSegmentId = "TDS" then sValue = oSegment.DataElementValue(1) 'Amount ElseIf sSegmentId = "CAD" then sValue = oSegment.DataElementValue(1) 'Transportation Method/Type Code sValue = oSegment.DataElementValue(2) 'Equipment Initial sValue = oSegment.DataElementValue(3) 'Equipment Number sValue = oSegment.DataElementValue(4) 'Standard Carrier Alpha Code sValue = oSegment.DataElementValue(5) 'Routing End If 'Segment ID ElseIf sLoopId = "ISS" then If sSegmentId = "ISS" then sValue = oSegment.DataElementValue(1) 'Number of Units Shipped sValue = oSegment.DataElementValue(2) 'Unit or Basis for Measurement Code EndIf 'sSegmentID EndIf 'sLoopID EndIf 'nArea 'GETS THE NEXT DATA SEGMENT Set oSegment = oSegment.Next Loop 'DESTROY OBJECTS Set oEdiDoc = Nothing Set oSchema = Nothing Set oSchemas = Nothing Set oSegment = Nothing