ADODB.Connection
(1)
SQL Server
(1)
ADODB.Recordset
(1)
OTransactionset.GetDataSegmentHeader
(1)
OInterchange.GetDataSegmentHeader
(1)
Office
(1)
Fredi.ediTransactionSet
(1)
Fredi.ediDataSegment
(1)

Need some advanced help on this one!

Asked By Earl.AKA J.Alladien in access forum!!
21-Nov-09 04:47 PM
Hi guys,

I found a sample Access program that takes data from its database to
generate an EDI EDIFACT ORDERS file (OrdersS93a.edi).

Here is the code:

Private Sub Command0_Click()
Dim oEdiDoc As Fredi.ediDocument
Dim oSchema As Fredi.ediSchema
Dim oInterchange As Fredi.ediInterchange
Dim oGroup As Fredi.ediGroup
Dim oTransactionset As Fredi.ediTransactionSet
Dim oSegment As Fredi.ediDataSegment

Dim oConn As ADODB.Connection
Dim oRsInterchange As ADODB.Recordset
Dim oRsGroup As ADODB.Recordset
Dim oRsTransactionSet As ADODB.Recordset
Dim oRsPOMaster As ADODB.Recordset
Dim oRsPODetail As ADODB.Recordset
Dim sConn As String

Dim sSefFile As String
Dim sEdiFile As String
Dim sPath As String

Dim i As Integer
Dim nCount As Integer
Dim sEntity As String
Dim nIndex As Integer
Dim iItemCount As Integer
Dim nInstance  As Integer
Dim mInstance As String

sPath = CurrentProject.Path & "\"

sConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & sPath &
Set oConn = New ADODB.Connection
oConn.Open sConn

'The InterchangeIndex table contains information of Interchange.
Set oRsInterchange = New ADODB.Recordset

'The TransactionSetIndex table contains information of the Transaction
Sets in the
'Interchanges
Set oRsTransactionSet = New ADODB.Recordset

'The POMaster table contains information of the Purchase Order in the
Transaction Set
Set oRsPOMaster = New ADODB.Recordset

'The PODetail table contains information of the detailed items of
Purchase Orders
Set oRsPODetail = New ADODB.Recordset

sSefFile = sPath & "ORDERS_S93A.sef"
sEdiFile = sPath & "ordersS93a.edi"

Set oEdiDoc = CreateObject("Fredi.ediDocument")
Set oSchema = oEdiDoc.LoadSchema(sSefFile, 0)

oEdiDoc.SegmentTerminator = "'"
oEdiDoc.ElementTerminator = "+"
oEdiDoc.CompositeTerminator = ":"
oEdiDoc.ReleaseIndicator = "?"

oRsInterchange.Open "Select * from InterchangeIndex", oConn,
adOpenDynamic, adLockOptimistic
Do While Not oRsInterchange.EOF
Set oInterchange = oEdiDoc.CreateInterchange("UN", "S93A")
Set oSegment = oInterchange.GetDataSegmentHeader
oSegment.DataElementValue(1, 1) = "UNOB"
oSegment.DataElementValue(1, 2) = "1"
oSegment.DataElementValue(2, 1) = oRsInterchange("SenderID").Value
oSegment.DataElementValue(2, 2) =
oRsInterchange("SenderID_Qlfr").Value
oSegment.DataElementValue(2, 3) = "MFGB"
oSegment.DataElementValue(3, 1) = oRsInterchange("ReceiverID").Value
oSegment.DataElementValue(3, 2) =
oRsInterchange("ReceiverID_Qlfr").Value
oSegment.DataElementValue(3, 3) = "ROUTE ADDR"
oSegment.DataElementValue(4, 1) = "970101"
oSegment.DataElementValue(4, 2) = "1230"
oSegment.DataElementValue(5) =
oRsInterchange("InterchangeControlNo").Value
oSegment.DataElementValue(7) = oRsInterchange("Application").Value
oSegment.DataElementValue(11) = "1"

oRsTransactionSet.Open "Select * from TransactionSetIndex where
InterchangeKey = " & oRsInterchange("InterchangeKey").Value, oConn,
adOpenDynamic, adLockOptimistic
Do While Not oRsTransactionSet.EOF
Set oTransactionset = oInterchange.CreateTransactionSet("ORDERS")
Set oSegment = oTransactionset.GetDataSegmentHeader
oSegment.DataElementValue(1) =
oRsTransactionSet("MessageRefNo").Value
oSegment.DataElementValue(2, 1) =

Fredi is probably an ActiveX control (or COM/DCOM component, they areclosely

Sylvain Lafontaine replied to Earl.AKA J.Alladien in access forum!!
21-Nov-09 06:29 PM
Fredi is probably an ActiveX control (or  COM/DCOM component, they are
closely related) that must be installed on your computer if you want to
instanciate it.  A quick search with Google indicate that this is probably
part of the EDI Framework but I am not sure:

http://www.edidev.com/menuevaluate.htm

--
Sylvain Lafontaine, ing.
MVP - Windows Live Platform
Blog/web site: http://coding-paparazzi.sylvainlafontaine.com
Independent consultant and remote programming for Access and SQL-Server
(French)

Hi Sylvain,Just so you know I did install the EDI framework, and the DB I

Earl.AKA J.Alladien in access forum!! replied to Sylvain Lafontaine
22-Nov-09 06:41 AM
Hi Sylvain,

Just so you know I did install the EDI framework, and the DB I downloaded
comes in 2 files one that generates from ACCESS to an EDI, and one that
translates an EDI into ACCESS, the last one works fine,...al references are
also set,so there is no problem there!

"Earl.AKA J.Alladien in access forum!!

Sylvain Lafontaine replied to Earl.AKA J.Alladien in access forum!!
22-Nov-09 12:49 PM
First, you should have given this information in the first place.

You should also explain if in the second file, the « Set oEdiDoc =
CreateObject("Fredi.ediDocument") » is working properly or if they is not any
of them.

If you are in the situation where the instruction « Set oEdiDoc =
CreateObject("Fredi.ediDocument") » works in one file but not in another,
then maybe the second file is corrupted or is partially wrongly compiled or
the references are not set correctly.

The first thing to do would be to fully decompile the faulty file and then
launch a full compilation from the Debug menu:

1- Open the References window from the VBA editor.

2- Add a dummy reference.

3- Close the References windows (Important!)

4- Reopen the References windows and remove the dummy reference (optional).

Now that the references has changed, Access will flag all modules as beeing
of need to be recompiled.  Launch the Recompile All Modules from the Debug
menu of the VBA editor.

Alternatively, create a windows shortcut with the following startup options:

/decompile /compact /repair

Another thing to try would be to use late binding instead of early binding:
replace the instruction « Dim oEdiDoc As Fredi.ediDocument » with « Dim
oEdiDoc As Object » or maybe even simply as a variant: « Dim oEdiDoc »

--
Sylvain Lafontaine, ing.
MVP - Windows Live Platform
Blog/web site: http://coding-paparazzi.sylvainlafontaine.com
Independent consultant and remote programming for Access and SQL-Server
(French)
Hi Sylvain,First of all I'd like to thank you for helping me ofcourse,And
Earl.AKA J.Alladien in access forum!! replied to Sylvain Lafontaine
23-Nov-09 01:02 PM
Hi Sylvain,

First of all I'd like to thank you for helping me ofcourse,

And after performing the "dummy" procedure it now works, so thanks a lot !!

Thanks again for your wisdom and advise!
You should perform this step everytime there is a big change in Windows
Sylvain Lafontaine replied to Earl.AKA J.Alladien in access forum!!
23-Nov-09 01:54 PM
You should perform this step everytime there is a big change in Windows (new
service pack, new version of Office, etc.) or when you are copying the MDFB
file to another machine; especially if the target machine does not have the
same version of Windows and Office.

--
Sylvain Lafontaine, ing.
MVP - Windows Live Platform
Blog/web site: http://coding-paparazzi.sylvainlafontaine.com
Independent consultant and remote programming for Access and SQL-Server
(French)
Post Question To EggHeadCafe