Sales Order Import Error

SUGGESTED

HELP!!!

'm getting a runtime  Error 440 < Error: 0 in Method ADDLINE> after the MsgBox "Add Lines"

What's the issue?

im Answer As String
Dim MyNote As String
 
    'Place your text here
    MyNote = "Import Orders into Sage?"
 
    'Display MessageBox
    Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "Orders")
 
    If Answer = vbYes Then
    DoCmd.SetWarnings False
    Me.Status = "Processing Sales Orders"

    ' Used to get MAS90\Home path
    Dim SOTAMAS90_DSN As Object
    Dim PVXCOM_InitPath As String

    ' ProvideX.Script Object
    Dim oPVX As Object

    ' ProvideX Objects (ProvideX.PvxDispatch)
    Dim oSS As Object
   
    Dim soINVOICE As Object

    ' Variables used as Parameters that will have their values changed on ProvideX method calls.
    ' These must be initialized with any value of their Data Type, Eg. 0 for Int, "" for strings,
    ' for their type to be recognized through COM.

    ' Numeric parameters
    Dim CheckQuantity As Integer
    Dim QuantityOrdered As Integer
    Dim tmpQuantityShipped As Integer
    Dim QuantityBackOrder As Integer
    Dim LineShipQty As Integer
    ' String Parameters
    Dim PONumber As String
    Dim LastPO As String
   
    Dim InvoiceNo As String
    Dim ItemCode As String
    Dim ItemType As String
    Dim JobNo As String
    Dim LineKey As String
    Dim LineSeqNo As String
    Dim OrderNo As String
    Dim LineOrderNo As String
    Dim LineItemNo As String
    Dim OrderDate As String
   
   
  
   
   
   

    ' Variables used for return values from ProvideX methods or as Parameters
    ' that will not have their value changed.  No need to initialize.

    ' Numeric return values
    Dim retVal, TaskID As Integer

'Get the path to mas90\home which is required by the Init() method
Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
oReg.GetExpandedStringValue &H80000001, "Software\ODBC\ODBC.INI\SOTAMAS90", "Directory", PathRoot
pathhome = PathRoot & "\Home"
Set oReg = Nothing

Set oScript = CreateObject("ProvideX.Script")
'oScript.Init("C:\Program Files\Sage Software\MAS 90\Version4\MAS90\Home")
oScript.Init (pathhome)

Set oSS = oScript.NewObject("SY_SESSION")

'The Logon method returns 1 if MAS90 Security is not enabled or if
'MAS90 has been configured to use Windows Security
retVal = oSS.nlogon()
'If the Logon method fails then you must use the SetUser method to be allowed access

If retVal = 0 Then
    'User = Trim(InputBox("Enter User Name"))
    User = "Admin"  '*** TEST
    'Password = Trim(InputBox("Enter Password"))
    Password = "xxyzzy" '**** TEST
    retVal = oSS.nSetUser(User, Password)
End If

'If the SetUser fails, display LastErrorMsg and quit
If retVal = 0 Then
    MsgBox (oSS.sLastErrorMsg & vbCrLf & "Quiting")
    'ERROR oSS.nCleanup()      ' Call Cleanup() before dropping the Session Object
    'ERROR oSS.DropObject()
    Set oSS = Nothing
    DoCmd.SetWarnings True
   Exit Sub
End If

'Set MAS 90 Company and Module
'Company must be configured to Allow External Access
retVal = oSS.nSetCompany("ABC")     '**** TEST

'If SetCompany fails, display LastErrorMsg and quit
If retVal = 0 Then
    MsgBox (oSS.sLastErrorMsg & vbCrLf & "Quiting")
    'ERROR oSS.nCleanup()      ' Call Cleanup() before dropping the Session Object
    'ERROR oSS.DropObject()
    Set oSS = Nothing
    DoCmd.SetWarnings True
     Exit Sub
End If

retVal = oSS.nSetDate("S/O", "20181001")
retVal = oSS.nSetModule("S/O")
'MsgBox "Test " & pathhome & User & Password

retVal = oSS.nSetProgram(oSS.nLookupTask("SO_SalesOrder_ui")) ' upper-case task name

If retVal = 0 Then
    MsgBox ("Unable to set program" & oSS.lastErrormsg)
     Set oSS = Nothing
     DoCmd.SetWarnings True
     Exit Sub
 End If


' S/O Order business object
oSEC = oSS.nSetProgram(oSS.nLookupTask("SO_SalesOrder_ui"))
Set oOrder = oScript.NewObject("SO_SalesOrder_bus", oSS)  '**** TEST
Set oLines = oScript.NewObject("SO_SalesOrderDetail_bus", oSS)

' Create a new header record using the next available invoice number

Dim dbs As DAO.Database
 Dim rstMain As DAO.Recordset
 Dim rstLine As DAO.Recordset
    Set dbs = CurrentDb()
 SqlStr = "SELECT * FROM OrderExport"
    Set rstMain = dbs.CreateQueryDef("", SqlStr).OpenRecordset
 
'loop through all table names
      
      
  With rstMain
        .MoveFirst
        LastPO = rstMain!PO_Number
        etVal = oOrder.nGetNextSalesOrderNo(OrderNo)
  Do Until rstMain.EOF
       
         PONumber = rstMain!PO_Number
         If PONumber <> LastPO Then
         ' Create header record using the next available order number
            r = 0
            r = oOrder.nGetNextSalesOrderNo(OrderNo)
         Else
         End If
         
         
         LineItemNo = rstMain!Line
         OrderDate = rstMain!ShipStart
         ShipTo = rstMain!ShipToCode
         ItemCode = rstMain!Model_Number
         QuantityOrdered = rstMain!Ordered
         QuantityBackOrder = rstMain!BackOrder
         LComment = rstMain!Comment
        
            
        
   MsgBox "Next Order no " & OrderNo & " PO Order no " & PONumber & " LineItemNo " & LineItemNo 'TEMP ****
         

r = oOrder.nSetValue("SalesOrderNo$", OrderNo)
r = oOrder.nSetValue("ARDivisonNo$", "01")
r = oOrder.nSetValue("CustomerNo$", "TEST")
r = oOrder.nSetValue("CustomerPONO$", PONumber)
r = oOrder.nSetValue("ShipExpireDate$", InvoiceDate)
MsgBox "Add lines"
                    r = oOrder.oLines.nAddLine()   '****TEMP
                    r = oOrder.oLines.nSetValue("ItemCode$", ItemCode)
                    r = oOrder.oLines.nSetValue("QuantityOrdered", QuantityOrdered)
                    r = oOrder.oLines.nSetValue("QuantityBackOrdered", QuantityBackOrder)
                    r = oOrder.oLines.nSetValue("CommentText$", LComment)
                    r = oOrder.oLines.nwrite()
                    If Not (r = 1) Then
                        Console.WriteLine ("Lines.Write fail: " + Order.oLines.sLastErrorMsg + vbCrLf + "ItemNumber: " + ItemCode)
                    End If


   If LastPO <> PONumber Then
   r = oOrder.nwrite()
   End If
   

    'Read next Order
    LastPO = PONumber
.MoveNext
 Loop
     
 End With   'Done with orders
Me.Status = ""

MsgBox "Import to Sales Invoice complete"

' Else
End If

  • 0
    SUGGESTED

    I don't believe you need this line:

    Set oLines = oScript.NewObject("SO_SalesOrderDetail_bus", oSS)

    oLines is inherited from oOrder so you can reference it without instantiating it.  I think this line is confusing it.

  • 0 in reply to hyanaga

    I removed the line and I still get the error.

  • 0
    SUGGESTED

    Based on your code and the lack of a SetKey method for the sales order header, i doubt your oOrder object is even creating a proper header record, if you were checking the returned values, i bet you'd see a message related to this.

    The GetNextSalesOrderNo method is meant to return the next sales order number in the variable you pass to it in the first and only argument.

    You still need to put the oOrder object into a record editing state by calling the SetKey method. Since the SalesOrderNo is the only field for the primary key, you can just call oOrder.nSetKey(OrderNo) and remove the oOrder.nSetValue("SalesOrderNo$", OrderNo) line.

  • 0 in reply to David Speck

    I did your suggestion with the same result.  The return value was 2.  It still errors out on the nAddline()

    r = oOrder.nSetKey(OrderNo)
    MsgBox "return " & r
    'r = oOrder.nSetValue("SalesOrderNo$", OrderNo)
    r = oOrder.nSetValue("ARDivisonNo$", "01")
    r = oOrder.nSetValue("CustomerNo$", "TEST")
    r = oOrder.nSetValue("CustomerPONO$", PONumber)
    r = oOrder.nSetValue("ShipExpireDate$", InvoiceDate)
    MsgBox "Add lines"
                        r = oOrder.oLines.nAddLine()   '****TEMP
                        r = oOrder.oLines.nSetValue("ItemCode$", ItemCode)

  • 0 in reply to jryals

    What about the return values for the subsequent SetValue methods?

    Try also checking the oOrder.sLastErrorMsg property after each method to see if anything useful pops up prior to the AddLine method.

  • 0 in reply to David Speck

    It's not creating the Sales Order.  Why?

     r = oOrder.nSetKey(OrderNo)
        MsgBox "return " & r                                                   "return 2"
        MsgBox (oOrder.sLastErrorMsg)                               "The 00000241 is invalid"
         
        r = oOrder.nSetValue("ARDivisonNo$", "01")
        MsgBox "DIV " & r                                                        "DIV 0"
          MsgBox (oOrder.sLastErrorMsg)                               "The column is not in the IOList.
        r = oOrder.nSetValue("CustomerNo$", "ABF")
        MsgBox "Cust " & r                                                        "Cust 0"
          MsgBox (oOrder.sLastErrorMsg)                                 "      "  
        r = oOrder.nSetValue("CustomerPONO$", PONumber)
        MsgBox "PO " & r                                                           "PO 0"
        r = oOrder.nSetValue("ShipExpireDate$", InvoiceDate)
        MsgBox "Date " & r                                                         "Date 0"
        MsgBox (oOrder.sLastErrorMsg)                                    "The customer number must be set".

  • 0 in reply to jryals

    Very interesting that your Order# is 8 characters, but the sales order field is only 7 characters.  I see that you're using the GetNextSalesOrderNo function, so this seems odd to me.  Can you test it with a hard-coded sales order number that's only 7 characters to see if that's the issue?

  • 0 in reply to jryals
    SUGGESTED

    Oh, a thought.  Do you initialize the OrderNo variable?  Might want to try adding that.

    OrderNo = ""

  • 0 in reply to hyanaga

    I tried hard coding sales order number "1234567", same result.

  • 0 in reply to hyanaga

    You wouldn't by chance have some code that works importing from Access, do you?