cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a Purchase Order

Former Member
0 Kudos

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)

vDrafts.Lines.Add()

End If

Next

'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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

change the code as

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
dim x as integer
x = 0
For i = 1 To oMatrix.RowCount
oCheck = oMatrix.Columns.Item("select").Cells.Item(i).Specific
If oCheck.Checked = True Then
x = x + 1
if x > 1 then
vDrafts.Lines.Add()
end if
'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
Next

'Add the Invoice
RetVal = vDrafts.Add

'Check the result
If RetVal 0 Then
oCompany.GetLastError(ErrCode, ErrMsg)
MsgBox(ErrCode & " " & ErrMsg)
End If
End Sub

Former Member
0 Kudos

Hi Petr Verner,

thanks for your fast answer! It solved the error problem, thank you!

But the purchase order wasnt supposed to be in the purchase order form in some registry?

Thanks you all.

Luis Barros

Former Member
0 Kudos

Sorry, but I dodnt undestand what you mean with sentence

"But the purchase order wasnt supposed to be in the purchase order form in some registry?"

Could you explain your needs more for me?

Former Member
0 Kudos

Hi again,

after adding a purchase order, from the code you correct and provide to me, this purchase order has to appear in the menu: "Purchase Order" form, right? In some registry.

I mean, everytime i need and create a purchase order from the code you provide me, that order will appear on the purchase order form, right? Example for consulting it or printing it. I open the purchase order form and search the orders i´ve created there, but nothing its there... Why?

Thank you

Luis Barros

Former Member
0 Kudos

Yes, you must be able to find the created order in purchase order form. If you cannot find it, something is wrong. Try to debug your code and check, if in variable RetVal is after adding the order 0 or something else. If is there 0, the order is created. Then the reason should be some permissions you have to view all orders. Then you should be able to check this with direct select to database with sql management studio as

select top 10 * from opor order by docentry desc

and check, if is there your order.

Former Member
0 Kudos

Hi again,

Its working, the problem was on this line: "vDrafts.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO"

ive deleted and its working.

i want to thank you very much for your help, it was very helpfull, ive already gave you points, you deserve them!

Thank you all

Luis Barros

Answers (0)