Private Sub cmdGenerate_Click() Dim oEdiDoc As Fredi.ediDocument Dim oSchema As Fredi.ediSchema Dim oSchemas As Fredi.ediSchemas Dim oInterchange As Fredi.ediInterchange Dim oGroup As Fredi.ediGroup Dim oTransactionset As Fredi.ediTransactionSet Dim oSegment As Fredi.ediDataSegment Dim sSefFile As String Dim sEdiFile As String Dim sPath As String sPath = Application.ActiveWorkbook.Path & "\" sSefFile = "IFTMIN_D99B.EVAL0.SEF" 'EVALUATION SEF FILE sEdiFile = "IFTMIN_D99B.edi" 'CREATES OEDIDOC 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 GENERATE THE EDI FILE. Set oSchemas = oEdiDoc.GetSchemas oSchemas.EnableStandardReference = False 'ENABLES FORWARD WRITE, AND INCREASES BUFFER I/O TO IMPROVE PERFORMANCE oEdiDoc.CursorType = Cursor_ForwardWrite oEdiDoc.Property(Property_DocumentBufferIO) = 200 'LOADS THE SEF FILE Set oSchema = oEdiDoc.LoadSchema(sPath & sSefFile, 0) 'SET TERMINATORS oEdiDoc.SegmentTerminator = "'{13:10}" oEdiDoc.ElementTerminator = "+" oEdiDoc.CompositeTerminator = ":" oEdiDoc.ReleaseIndicator = "?" 'CREATES THE UNB SEGMENT Set oInterchange = oEdiDoc.CreateInterchange("UN", "D99B") Set oSegment = oInterchange.GetDataSegmentHeader oSegment.DataElementValue(1, 1) = "UNOA" 'Syntax identifier oSegment.DataElementValue(1, 2) = "1" 'Syntax version number oSegment.DataElementValue(2, 1) = "SENDER_ID" 'Interchange sender identification oSegment.DataElementValue(2, 2) = "ZZZ" 'Partner identification code qualifier oSegment.DataElementValue(3, 1) = "RECEIVER_ID" 'Recipient identification oSegment.DataElementValue(3, 2) = "ZZZ" 'Partner identification code qualifier oSegment.DataElementValue(4, 1) = "001002" 'Date oSegment.DataElementValue(4, 2) = "0900" 'Time oSegment.DataElementValue(5) = "324157" 'Interchange control reference oSegment.DataElementValue(6) = "005690" 'Recipient reference/password oSegment.DataElementValue(7) = "IFTMIN" 'Application reference 'CREATES THE UNH SEGMENT Set oTransactionset = oInterchange.CreateTransactionSet("IFTMIN") Set oSegment = oTransactionset.GetDataSegmentHeader oSegment.DataElementValue(1) = "1234567" 'Message reference number oSegment.DataElementValue(2, 1) = "IFTMIN" 'Message type identifier oSegment.DataElementValue(2, 2) = "D" 'Message version number oSegment.DataElementValue(2, 3) = "99B" 'Message release number oSegment.DataElementValue(2, 4) = "UN" 'Controlling agency 'BGM - BEGINNING OF MESSAGE Set oSegment = oTransactionset.CreateDataSegment("BGM") oSegment.DataElementValue(1, 1) = "340" 'Document/message name, coded oSegment.DataElementValue(1, 4) = "LDN" 'Document/message name oSegment.DataElementValue(2, 1) = "CUSTOMER_ASSIGNED_NO" 'Document/message number oSegment.DataElementValue(3) = "9" 'Message function, coded 'DTM - DATE/TIME/PERIOD Set oSegment = oTransactionset.CreateDataSegment("DTM") oSegment.DataElementValue(1, 1) = "137" 'Date/time/period qualifier oSegment.DataElementValue(1, 2) = "19980112" 'Date/time/period oSegment.DataElementValue(1, 3) = "102" 'Date/time/period format qualifier 'TSR - TRANSPORT SERVICE REQUIREMENTS Set oSegment = oTransactionset.CreateDataSegment("TSR") oSegment.DataElementValue(2, 1) = "2" 'Service requirement, coded oSegment.DataElementValue(2, 4) = "2" 'Service requirement, coded 'FTX - FREE TEXT Set oSegment = oTransactionset.CreateDataSegment("FTX") oSegment.DataElementValue(1) = "AAI" 'Text subject qualifier oSegment.DataElementValue(4, 1) = "FREE TEXT MESSAGE" 'Free text 'GDS - NATURE OF CARGO Set oSegment = oTransactionset.CreateDataSegment("GDS") oSegment.DataElementValue(1, 1) = "12" 'Nature of cargo, coded oSegment.DataElementValue(1, 2) = "161" 'Code list qualifier 'LOC - PLACE/LOCATION IDENTIFICATION Set oSegment = oTransactionset.CreateDataSegment("LOC\LOC") oSegment.DataElementValue(1) = "7" 'Place/location qualifier oSegment.DataElementValue(2, 1) = "GBLDS" 'Place/location identification 'RFF - REFERENCE Set oSegment = oTransactionset.CreateDataSegment("RFF\RFF") oSegment.DataElementValue(1, 1) = "BN" 'Reference qualifier oSegment.DataElementValue(1, 2) = "SOUA12345" 'Reference number 'RFF - REFERENCE Set oSegment = oTransactionset.CreateDataSegment("RFF(2)\RFF") oSegment.DataElementValue(1, 1) = "AFG" 'Reference qualifier oSegment.DataElementValue(1, 2) = "MLCC" 'Reference number 'RFF - REFERENCE Set oSegment = oTransactionset.CreateDataSegment("RFF(3)\RFF") oSegment.DataElementValue(1, 1) = "AGT" 'Reference qualifier oSegment.DataElementValue(1, 3) = "88" 'Line number 'GOR - GOVERNMENTAL REQUIREMENTS Set oSegment = oTransactionset.CreateDataSegment("GOR\GOR") oSegment.DataElementValue(1) = "1" 'Transport movement, coded oSegment.DataElementValue(2, 1) = "5" 'Government agency, coded oSegment.DataElementValue(2, 2) = "4" 'Government involvement, coded oSegment.DataElementValue(2, 3) = "1" 'Government action, coded 'CPI - CHARGE PAYMENT INSTRUCTIONS Set oSegment = oTransactionset.CreateDataSegment("CPI\CPI") oSegment.DataElementValue(1, 1) = "1" 'Charge category, coded oSegment.DataElementValue(3) = "P" 'Prepaid/collect indicator, coded 'TDT - TRANSPORT INFORMATION Set oSegment = oTransactionset.CreateDataSegment("TDT\TDT") oSegment.DataElementValue(1) = "20" 'Transport stage qualifier oSegment.DataElementValue(2) = "V1234" 'Conveyance reference number oSegment.DataElementValue(3, 1) = "1" 'Mode of transport, coded oSegment.DataElementValue(5, 1) = "MAE" 'Carrier identification oSegment.DataElementValue(5, 3) = "166" 'Code list responsible agency, coded oSegment.DataElementValue(8, 1) = "7825411" 'Id. of means of transport identification oSegment.DataElementValue(8, 2) = "103" 'Code list qualifier oSegment.DataElementValue(8, 3) = "11" 'Code list responsible agency, coded oSegment.DataElementValue(8, 4) = "VESSEL ID." 'Id. of the means of transport oSegment.DataElementValue(8, 5) = "PA" 'Nationality of means of transport, coded 'LOC - PLACE/LOCATION IDENTIFICATION Set oSegment = oTransactionset.CreateDataSegment("TDT\LOC\LOC") oSegment.DataElementValue(1) = "11" 'Place/location qualifier oSegment.DataElementValue(2, 1) = "HKHKG" 'Place/location identification 'DTM - DATE/TIME/PERIOD Set oSegment = oTransactionset.CreateDataSegment("TDT\LOC\DTM") oSegment.DataElementValue(1, 1) = "132" 'Date/time/period qualifier oSegment.DataElementValue(1, 2) = "19980112" 'Date/time/period oSegment.DataElementValue(1, 3) = "102" 'Date/time/period format qualifier 'NAD - NAME AND ADDRESS Set oSegment = oTransactionset.CreateDataSegment("NAD\NAD") oSegment.DataElementValue(1) = "CZ" 'Party qualifier oSegment.DataElementValue(2, 1) = "130LDN100" 'Party identification oSegment.DataElementValue(3, 1) = "ABC SHIP CO." 'Name and address line oSegment.DataElementValue(3, 2) = "123 COAST PORT ST." 'Name and address line oSegment.DataElementValue(3, 3) = "WHAREHOUSE ST" 'Name and address line" oSegment.DataElementValue(3, 4) = "LONG BEACH" 'Name and address line oSegment.DataElementValue(3, 5) = "89242" 'Name and address line 'CTA - CONTACT INFORMATION Set oSegment = oTransactionset.CreateDataSegment("NAD\CTA\CTA") oSegment.DataElementValue(1) = "IC" 'Contact function, coded oSegment.DataElementValue(2, 2) = "JANE SMITH" 'Department or employee 'COM - COMMUNICATION CONTACT Set oSegment = oTransactionset.CreateDataSegment("NAD\CTA\COM") oSegment.DataElementValue(1, 1) = "555555125184" 'Communication number oSegment.DataElementValue(1, 2) = "TE" 'Communication channel qualifier 'DOC - DOCUMENT/MESSAGE DETAILS Set oSegment = oTransactionset.CreateDataSegment("NAD\DOC\DOC") oSegment.DataElementValue(1, 1) = "705" 'Document/message name, coded oSegment.DataElementValue(4) = "2" 'Number of copies of document required oSegment.DataElementValue(5) = "2" 'Number of originals of document required 'CPI - CHARGE PAYMENT INSTRUCTIONS Set oSegment = oTransactionset.CreateDataSegment("NAD\CPI\CPI") oSegment.DataElementValue(1, 1) = "8" 'Charge category, coded oSegment.DataElementValue(3) = "P" 'Prepaid/collect indicator, coded 'GID - GOODS ITEM DETAILS Set oSegment = oTransactionset.CreateDataSegment("GID\GID") oSegment.DataElementValue(1) = "1" 'Goods item number oSegment.DataElementValue(3, 1) = "3" 'Number of packages oSegment.DataElementValue(3, 2) = "CT" 'Type of packages identification 'TMP - TEMPERATURE Set oSegment = oTransactionset.CreateDataSegment("GID\TMP") oSegment.DataElementValue(1) = "2" 'Temperature qualifier oSegment.DataElementValue(2, 1) = "-04.5" 'Temperature setting oSegment.DataElementValue(2, 2) = "CEL" 'Measure unit qualifier 'TMD - TRANSPORT MOVEMENT DETAILS Set oSegment = oTransactionset.CreateDataSegment("GID\TMD") oSegment.DataElementValue(1, 1) = "3" 'Movement type, coded 'FTX - FREE TEXT Set oSegment = oTransactionset.CreateDataSegment("GID\FTX") oSegment.DataElementValue(1) = "AAA" 'Text subject qualifier oSegment.DataElementValue(4, 1) = "GOODS DESCRIPTION ONLY" 'Free text 'MEA - MEASUREMENTS Set oSegment = oTransactionset.CreateDataSegment("GID\MEA\MEA") oSegment.DataElementValue(1) = "AAE" 'Measurement purpose qualifier oSegment.DataElementValue(2, 1) = "G" 'Property measured, coded oSegment.DataElementValue(3, 1) = "KGM" 'Measure unit qualifier oSegment.DataElementValue(3, 2) = "1000" 'Measurement value 'RFF - REFERENCE Set oSegment = oTransactionset.CreateDataSegment("GID\RFF\RFF") oSegment.DataElementValue(1, 1) = "AED" 'Reference qualifier oSegment.DataElementValue(1, 2) = "180100" 'Reference number 'PCI - PACKAGE IDENTIFICATION Set oSegment = oTransactionset.CreateDataSegment("GID\PCI\PCI") oSegment.DataElementValue(1) = "23" 'Marking instructions, coded oSegment.DataElementValue(2, 1) = "MARKS AND NUMBERS" 'Shipping marks 'SGP - SPLIT GOODS PLACEMENT Set oSegment = oTransactionset.CreateDataSegment("GID\SGP\SGP") oSegment.DataElementValue(1, 1) = "MAEU1234567" 'Equipment identification number oSegment.DataElementValue(2) = "3" 'Number of packages 'MEA - MEASUREMENTS Set oSegment = oTransactionset.CreateDataSegment("GID\SGP\MEA\MEA") oSegment.DataElementValue(1) = "AAE" 'Measurement purpose qualifier oSegment.DataElementValue(2, 1) = "G" 'Property measured, coded oSegment.DataElementValue(3, 1) = "KGM" 'Measure unit qualifier oSegment.DataElementValue(3, 2) = "1000" 'Measurement value 'TCC - CHARGE/RATE CALCULATIONS Set oSegment = oTransactionset.CreateDataSegment("GID\TCC\TCC") oSegment.DataElementValue(1, 1) = "BAS" 'Freight and charges identification oSegment.DataElementValue(1, 4) = "BASIC OCEAN FREIGHT" 'Freight and charges oSegment.DataElementValue(1, 5) = "P" 'Prepaid/collect indicator, coded 'PRI - PRICE DETAILS Set oSegment = oTransactionset.CreateDataSegment("GID\TCC\PRI") oSegment.DataElementValue(1, 1) = "CAL" 'Price qualifier oSegment.DataElementValue(1, 2) = "2250.00" 'Price oSegment.DataElementValue(1, 6) = "40" 'Measure unit qualifier oSegment.DataElementValue(2) = "A" 'Sub-line price change, coded 'MOA - MONETARY AMOUNT Set oSegment = oTransactionset.CreateDataSegment("GID\TCC\MOA") oSegment.DataElementValue(1, 1) = "64" 'Monetary amount type qualifier oSegment.DataElementValue(1, 2) = "2250.00" 'Monetary amount oSegment.DataElementValue(1, 3) = "USD" 'Currency, coded 'QTY - QUANTITY Set oSegment = oTransactionset.CreateDataSegment("GID\TCC\QTY") oSegment.DataElementValue(1, 1) = "107" 'Quantity qualifier oSegment.DataElementValue(1, 2) = "1.000" 'Quantity 'DGS - DANGEROUS GOODS Set oSegment = oTransactionset.CreateDataSegment("GID\DGS\DGS") oSegment.DataElementValue(1) = "IMD" 'Dangerous goods regulations, coded oSegment.DataElementValue(2, 1) = "3.3" 'Hazard code identification oSegment.DataElementValue(2, 2) = "3372" 'Hazard substance/item/page number oSegment.DataElementValue(3, 1) = "1263" 'UNDG number oSegment.DataElementValue(4, 1) = "028" 'Shipment flashpoint oSegment.DataElementValue(4, 2) = "CEL" 'Measure unit qualifier oSegment.DataElementValue(5) = "3" 'Packing group, coded oSegment.DataElementValue(6) = "3.06" 'EMS number oSegment.DataElementValue(7) = "305" 'MFAG 'FTX - FREE TEXT Set oSegment = oTransactionset.CreateDataSegment("GID\DGS\FTX") oSegment.DataElementValue(1) = "AAD" 'Text subject qualifier oSegment.DataElementValue(4, 1) = "TECHNICAL NAME" 'Free text 'CTA - CONTACT INFORMATION Set oSegment = oTransactionset.CreateDataSegment("GID\DGS\CTA\CTA") oSegment.DataElementValue(1) = "HG" 'Contact function, coded oSegment.DataElementValue(2, 2) = "JOHN POWELL" 'Department or employee 'COM - COMMUNICATION CONTACT Set oSegment = oTransactionset.CreateDataSegment("GID\DGS\CTA\COM") oSegment.DataElementValue(1, 1) = "441717125184" 'Communication number oSegment.DataElementValue(1, 2) = "TE" 'Communication channel qualifier 'MEA - MEASUREMENTS Set oSegment = oTransactionset.CreateDataSegment("GID\DGS\MEA\MEA") oSegment.DataElementValue(1) = "AAE" 'Measurement purpose qualifier oSegment.DataElementValue(2, 1) = "G" 'Property measured, coded oSegment.DataElementValue(3, 1) = "KGM" 'Measure unit qualifier oSegment.DataElementValue(3, 2) = "1000" 'Measurement value 'SGP - SPLIT GOODS PLACEMENT Set oSegment = oTransactionset.CreateDataSegment("GID\DGS\SGP\SGP") oSegment.DataElementValue(1, 1) = "MAEU1234567" 'Equipment identification number oSegment.DataElementValue(2) = "3" 'Number of packages 'MEA - MEASUREMENTS Set oSegment = oTransactionset.CreateDataSegment("GID\DGS\SGP\MEA\MEA") oSegment.DataElementValue(1) = "AAE" 'Measurement purpose qualifier oSegment.DataElementValue(2, 1) = "G" 'Property measured, coded oSegment.DataElementValue(3, 1) = "KGM" 'Measure unit qualifier oSegment.DataElementValue(3, 2) = "1000" 'Measurement value 'EQD - EQUIPMENT DETAILS Set oSegment = oTransactionset.CreateDataSegment("EQD\EQD") oSegment.DataElementValue(1) = "CN" 'Equipment qualifier oSegment.DataElementValue(2, 1) = "MAEU1234567" 'Equipment identification number oSegment.DataElementValue(3, 1) = "42" 'Equipment size and type identification oSegment.DataElementValue(3, 3) = "5" 'Code list responsible agency, coded 'TMD - TRANSPORT MOVEMENT DETAILS Set oSegment = oTransactionset.CreateDataSegment("EQD\TMD") oSegment.DataElementValue(3) = "1" 'Haulage arrangements, coded 'SEL - SEAL NUMBER Set oSegment = oTransactionset.CreateDataSegment("EQD\SEL") oSegment.DataElementValue(1) = "ML12345" 'Seal number oSegment.DataElementValue(2, 1) = "CA" 'Sealing party, coded 'TRAILING SEGMENTS ARE AUTOMATICALLY CREATED WHEN FREDI COMMITS (SAVES) THE EDIDOC OBJECT INTO A FILE. oEdiDoc.Save sPath & sEdiFile 'display edi string MsgBox oEdiDoc.GetEdiString 'DESTROYS OBJECTS Set oSegment = Nothing Set oTransactionset = Nothing Set oGroup = Nothing Set oSchema = Nothing Set oInterchange = Nothing Set oEdiDoc = Nothing End Sub