Skip to Content
Former Member
Jun 23, 2008 at 01:54 PM

Creating a Purchase Order


Hi there,

i need to create an purchase order, heres my code:

Private Sub Gerarcompra()

Dim i As Integer

Dim RetVal As Long

Dim ErrCode As Long

Dim ErrMsg As String

ErrMsg = "Ocorreu um erro..."

Dim vDrafts As SAPbobsCOM.Documents

vDrafts = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders)

oForm = SBO_Application.Forms.Item("analprocform")

oMatrix = oForm.Items.Item("MatrixProc").Specific

For i = 1 To oMatrix.RowCount

oCheck = oMatrix.Columns.Item("select").Cells.Item(i).Specific

If oCheck.Checked = True Then

'Set values to the fields

vDrafts.CardCode = "V8000"

vDrafts.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO

vDrafts.DocDate = System.DateTime.Now

'Invoice Lines - Set values to the first line

oEditText = oMatrix.Columns.Item("NArtigo").Cells.Item(i).Specific

vDrafts.Lines.ItemCode = oEditText.Value

vDrafts.Lines.ItemDescription = ""

oEditText = oMatrix.Columns.Item("Quantidade").Cells.Item(i).Specific

vDrafts.Lines.Quantity = Double.Parse(oEditText.Value)

oEditText = oMatrix.Columns.Item("Preco").Cells.Item(i).Specific

vDrafts.Lines.UnitPrice = Double.Parse(oEditText.Value)


End If


'Add the Invoice

RetVal = vDrafts.Add

'Check the result

If RetVal <> 0 Then

oCompany.GetLastError(ErrCode, ErrMsg)

MsgBox(ErrCode & " " & ErrMsg)

End If

End Sub

But in the end i got an error: "Nº Article missing...".

Thank you all for your support.

Luis Barros