Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create OE Order with Macro - Automation error 1

Status
Not open for further replies.

johnhugh

Technical User
Mar 24, 2010
702
SG
Hi,
I'm trying to insert an OE order in Accpac 5.6.
I've recorded a macro and made some modification, however when running my code I get 'Automation error. Unspecified error'

It fails at the point where I want to insert the detail line: OEORD1detail1.Insert

Would someone be able to provide a sample code of inserting an OE order or let me know what I'm doing wrong in my code below.

Code:
mDBLinkCmpRW.OpenView "OE0520", OEORD1header
    Set OEORD1headerFields = OEORD1header.Fields
    mDBLinkCmpRW.OpenView "OE0500", OEORD1detail1
    Set OEORD1detail1Fields = OEORD1detail1.Fields
    mDBLinkCmpRW.OpenView "OE0740", OEORD1detail2
    Set OEORD1detail2Fields = OEORD1detail2.Fields
    mDBLinkCmpRW.OpenView "OE0180", OEORD1detail3
    Set OEORD1detail3Fields = OEORD1detail3.Fields
    mDBLinkCmpRW.OpenView "OE0526", OEORD1detail5
    Set OEORD1detail5Fields = OEORD1detail5.Fields
    mDBLinkCmpRW.OpenView "OE0522", OEORD1detail6
    Set OEORD1detail6Fields = OEORD1detail6.Fields
    mDBLinkCmpRW.OpenView "OE0501", OEORD1detail7
    Set OEORD1detail7Fields = OEORD1detail7.Fields
    mDBLinkCmpRW.OpenView "OE0502", OEORD1detail8
    Set OEORD1detail8Fields = OEORD1detail8.Fields
    mDBLinkCmpRW.OpenView "OE0504", OEORD1detail9
    Set OEORD1detail9Fields = OEORD1detail9.Fields
    mDBLinkCmpRW.OpenView "OE0503", OEORD1detail10
    Set OEORD1detail10Fields = OEORD1detail10.Fields

Code:
Private Function LoadOrder(customer As String, poNumber As String, itemNo() As String, quantity() As Double, unitCost() As Currency, description As String, reference As String)
    
    OEORD1header.Compose Array(OEORD1detail1, Nothing, OEORD1detail3, OEORD1detail2, OEORD1detail5, OEORD1detail6)
    OEORD1detail1.Compose Array(OEORD1header, OEORD1detail7, OEORD1detail10, OEORD1detail8)
    OEORD1detail2.Compose Array(OEORD1header)
    OEORD1detail3.Compose Array(OEORD1header, OEORD1detail1)
    OEORD1detail5.Compose Array(OEORD1header)
    OEORD1detail6.Compose Array(OEORD1header)
    OEORD1detail7.Compose Array(OEORD1detail1)
    OEORD1detail8.Compose Array(OEORD1detail1, OEORD1detail9)
    OEORD1detail9.Compose Array(OEORD1detail8)
    OEORD1detail10.Compose Array(OEORD1detail1)
   
    OEORD1header.Cancel
    OEORD1header.Init
    OEORD1detail2.Browse "", 1
    OEORD1detail2.Fetch
    OEORD1headerFields("CUSTOMER").Value = customer                     ' Customer Number
    
    OEORD1detail2.Browse "", 1
    OEORD1detail2Fields("PAYMENT").PutWithoutVerification ("-32767")   ' Payment Number
    OEORD1detail2.Browse "", -1
    OEORD1detail2.Fetch
    OEORD1headerFields("PROCESSCMD").PutWithoutVerification ("1")       ' Process OIP Command
    OEORD1header.Process
    
    OEORD1headerFields("SHIPTO").Value = "10GEI"                        ' Ship-To Location Code
    OEORD1headerFields("GOFCALCTAX").PutWithoutVerification ("1")       ' Perform Forced Tax Calculation
    OEORD1header.Process
    OEORD1headerFields("PROCESSCMD").PutWithoutVerification ("1")       'Process OIP Command
    OEORD1header.Process
    
    OEORD1headerFields("PONUMBER").Value = poNumber                    ' Purchase Order Number
    OEORD1headerFields("EXPDATE").Value = expShipDate                   ' Expected Ship Date
    OEORD1headerFields("ORDDATE").Value = DateSerial(2011, 6, 3)         ' Order Date
   
        OEORD1headerFields("REFERENCE").PutWithoutVerification ("ref")        ' Order Reference
    OEORD1headerFields("DESC").PutWithoutVerification ("desc")            ' Order Description
    
    OEORD1header.Process
    OEORD1header.Insert
    OEORD1header.Order = 1
    OEORD1header.Read
    OEORD1header.Order = 0
    
    OEORD1detail2Fields("PAYMENT").PutWithoutVerification ("-32767")      ' Payment Number
    OEORD1detail2.Browse "", -1
    OEORD1detail2.Fetch
   
    OEORD1detail1.RecordClear
        
    Dim i As Integer
    For i = 1 To numOfLines                                                     'insert detail lines
        OEORD1detail1.Read
        OEORD1detail1.RecordCreate 0
        
        OEORD1detail1Fields("ITEM").Value = itemNo(i)                           ' Item
        OEORD1detail1.Process
        OEORD1detail1Fields("QTYORDERED").Value = quantity(i)                  ' Quantity Ordered
        OEORD1detail1Fields("PROCESSCMD").PutWithoutVerification ("1")          ' Process Command
        OEORD1detail1.Insert
    Next i
    
End Function
 
Automation error. Unspecified error is all I get from the error handler.
 
Add an Accpac error handler, you will get the Accpac error.
 
I might be doing something wrong but I thing I'm using the Accpac error handler already.

Has anyone got a working example of entering an O/E order which I can test?

Code:
ACCPACErrorHandler:
  Dim lCount As Long
  Dim lIndex As Long
  error = True
  If Errors Is Nothing Then
       MsgBox Err.description
  Else
      lCount = Errors.Count

      If lCount = 0 Then
          MsgBox Err.description
      Else
          For lIndex = 0 To lCount - 1
              MsgBox Errors.Item(lIndex)
          Next
          Errors.Clear
      End If
      Resume Next
  End If
 
Your code has lots of junk in it. It only needs to be this:

OEORD1header.Cancel
OEORD1header.Init
OEORD1headerFields("CUSTOMER").Value = Customer
OEORD1headerFields("SHIPTO").Value = "10GEI"
OEORD1headerFields("PONUMBER").Value = poNumber
OEORD1headerFields("EXPDATE").Value = expShipDate
OEORD1headerFields("ORDDATE").Value = DateSerial(2011, 6, 3)
OEORD1headerFields("REFERENCE").PutWithoutVerification ("ref")
OEORD1headerFields("DESC").PutWithoutVerification ("desc")

For i = 1 To numOfLines
OEORD1detail1.Read
OEORD1detail1.RecordCreate 0
OEORD1detail1Fields("ITEM").Value = itemNo(i)
OEORD1detail1Fields("QTYORDERED").Value = quantity(i)
OEORD1detail1Fields("PROCESSCMD").PutWithoutVerification ("1")
OEORD1detail1.Insert
Next i

OEORD1header.Insert
 
Thanks so much tuba!
Your code works for me.

Its hard to tell from the macro what is junk and really needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top