on 02-22-2012 1:28 AM
Hi Expert,
Where should I put the vDrafts.Lines.Add?
we need to put the "vDrafts.Lines.Add" But it is not need for the 1st line.
rstGRA1 is the recordset of the line detail
rstGRA1.MoveFirst
Do While Not rstGRA1.EOF
vDrafts.Lines.ItemCode = rstGRA1.Fields("U_Itemcode")
vDrafts.Lines.Quantity = rstGRA1.Fields("Quantity")
rstGRA1.MoveNext
Loop
Thanks a lot
Best regards
Gary
Got it
thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I use following code, but it seems to be have a better solution. Could you please rewrite it. Thanks a lot
'draft line - set values to the first line
rstGRA1.MoveFirst
If Not rstGRA1.EOF Then
vDrafts.Lines.ItemCode = rstGRA1.Fields("U_Itemcode")
vDrafts.Lines.Quantity = rstGRA1.Fields("Quantity")
vDrafts.Lines.UnitPrice = rstGRA1.Fields("price")
End If
'For ongoing line
rstGRA1.MoveNext
Do While Not rstGRA1.EOF
vDrafts.Lines.Add
vDrafts.Lines.ItemCode = rstGRA1.Fields("U_Itemcode")
vDrafts.Lines.Quantity = rstGRA1.Fields("Quantity")
vDrafts.Lines.UnitPrice = rstGRA1.Fields("price")
rstGRA1.MoveNext
Loop
Hi Gary,
It depends a bit, on the source type of your data, but the general idea is to keep count of the rows, and add a new line only if another row is forthcoming.
The SDK's own example uses a DataTable (DataGrid)
Dim i As Integer
i = 0
Do
oOrder.Lines.ItemCode = TableLines.Rows(i).Item(0)
oOrder.Lines.ItemDescription = TableLines.Rows(i).Item(1)
oOrder.Lines.Quantity = TableLines.Rows(i).Item(2)
oOrder.Lines.Price = TableLines.Rows(i).Item(3)
oOrder.Lines.TaxCode = TableLines.Rows(i).Item(4)
oOrder.Lines.LineTotal = TableLines.Rows(i).Item(5)
i += 1
If i <> TableLines.Rows.Count Then
oOrder.Lines.Add()
End If
Loop Until i = TableLines.Rows.Count
I use a DataSet myself:
'Doc is a B1 order object
With Doc
For Each rw As DataRow In MyDataSet.Tables("TableName").Rows
.Lines.ItemCode = rw.Item(cn_ItemCode)
.Lines.Quantity = rw.Item(cn_Quantity)
.Lines.Price = rw.Item(cn_Price)
.Lines.UserFields.Fields.Item("U_CustLineNum").Value = rw.Item(cn_LineNum)
'SBO creates the first row automatically.
'Add a new row only if necessary
If _Rows.Rows.IndexOf(rw) < _Rows.Rows.Count Then .Lines.Add()
Next
End With
See if you can do something with this.
Good luck,
Johan
Edited by: Johan Hakkesteegt on Feb 23, 2012 8:39 AM
looking for rewrite
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got it thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
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.