on 06-23-2008 2:54 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
User | Count |
---|---|
107 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.