Skip to Content
Former Member
Mar 01, 2007 at 08:39 AM

CopyFrom SalesOrder To ProductionOrder


Hi ,

I am doing a copy to functionality, wherein my code is copying from Orders to Invoice. But when I try to copy from Orders to Production Order it gives me an error on the following line :

oPO = MyCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductionOrders)

Error :

Invalid Cast Exception was unhandled

Unable to cast COM object of type 'System.__ComObject' to interface type 'SAPbobsCOM.Documents'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A6DA575B-E105-4585-9F4B-50CC4044EEDD}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I have to do a CopyFrom SalesOrders and CopyTo ProductionOrders on the click of Add Button of SalesOrder. Here is the code what I am executing.

Dim MyCompany As SAPbobsCOM.Company

Dim odocs As SAPbobsCOM.Documents

Dim oPO As SAPbobsCOM.Documents

odocs = MyCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)

odocs.CardCode = "c0001"

odocs.DocDate = Now

odocs.DocDueDate = Now

odocs.Lines.ItemCode = "A00007"

Ret = odocs.Add

Dim x As String

Dim IErrCode As Integer


If Ret <> 0 Then

MyCompany.GetLastError(IErrCode, x)



MsgBox("Order Created " & x & ".")

End If


End Sub

Public Sub createProductionOrder(ByVal x As String)

oPO = MyCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductionOrders) Β‘on the this line it gives the error as mentioned above.

oPO.DocNum = x

oPO.DocDate = Now

oPO.DocDueDate = Now

oPO.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oOrders

oPO.Lines.BaseEntry = x

Ret = oPO.Add

Dim IErrCode As Integer

If Ret <> 0 Then

MyCompany.GetLastError(IErrCode, x)



MsgBox("Production Order Created " & x & ".")

End If

End Sub

Thanks if any one can look into the code and give me the correct code to solve my solution of Coping the SalesOrders to ProductionOrder. Or can give me an alterante code/solution.