Error  -10  while closing a Production Order with DI API

Hi,
I've been trying to close some production orders using this code:
Dim oProdOrder As SAPbobsCOM.ProductionOrders
        Try
            oProdOrder = Me.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductionOrders)
            If oProdOrder.GetByKey(intDocEntry) Then
                oProdOrder.ProductionOrderStatus = SAPbobsCOM.BoProductionOrderStatusEnum.boposClosed
                If oProdOrder.Update <> 0 Then
                    Me.Company.GetLastError(intError, sErrMsg)
                    If (0 <> intError) Then
                        sErrorMsg = sErrorMsg & "Production Order Close Error: " & CStr(intError) & "," & sErrMsg & _
                            ". DocEntry: " & oProdOrder.ProductionOrderOriginEntry & vbCrLf
                    End If
                End If
            End If
...But I keep getting the same error every time I try: -10,Date out of reference date range, '_SYS00000005340'
The error doesn't show when I close the Order with BO's Form. And I've checked the exchange rate for the posting and due date of the document (and also for my current date) and there seems to be no problem with it.
I'm currently working with SAP BO 2004A PL 45.
Anybody has a suggestion? a workaround?
I'll appreciate any help you can give me.
Thanks in advance...
Alfredo

Alfredo,
just in case,
what is the previous state of the production order (planned, released,...)?
before you try to close the order, update the status to released:
If oProdOrder.GetByKey(newID) Then
'Cambio di stato dell'ordine da 'Planned' a 'Released'
                oProdOrder.ProductionOrderStatus = boposReleased
oProdOrder.Update
I found this code in a DI API application written for 2004A. It was commented out so I suspect it didn't work.
'Chiusura dell 'ordine
        'SelProductionOrder.ProductionOrderStatus = boposClosed
        'ret = SelProductionOrder.Update
        'If ret <> 0 Then
        '    sboCompany.GetLastError nErr, errMsg
        '    MsgBox "Errore " & nErr & " - " & errMsg
        'End If
Hope this helps

Similar Messages

Maybe you are looking for