hello,
I create a user table.
I want to fill a matrix on a form with some aggregated data of this user table.
I do :
Public Sub SetMatrixRep()
Dim oRecordSet As SAPbobsCOM.Recordset
Dim oCentre As SAPbouiCOM.EditText
Dim oCompte As SAPbouiCOM.EditText
Dim oBudget As SAPbouiCOM.EditText
Dim oDepense As SAPbouiCOM.EditText
Dim oSolde As SAPbouiCOM.EditText
Dim i As Long
i = 0
Set oRecordSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
oRecordSet.DoQuery ("select * from [@CAP_OPRC_BUDGET]")
While oRecordSet.EOF = False
' filling the matrix
Set oCentre = oMatrixRep.Columns("clCentre").Cells.Item(i).Specific
oCentre.String = oRecordSet.Fields.Item(0).Value
'oMatrixRep.Columns("clCentre").Cells(1).Specific.String = oRecordSet.Fields.Item(0).Value
'SBO_Application.MessageBox (oRecordSet.Fields.Item(0).Value)
oMatrixRep.AddRow
oRecordSet.MoveNext
i = i + 1
Wend
End Sub
I've got an error : Row - Index invalid.
Could you help me please ?
Thanks.
Romeo.
Hi
This is a routine that I call from my Item Event handler
Hope it can help you
Public Sub PopolaMatrice(oApplicazione As SAPbouiCOM.Application, pVal As SAPbouiCOM.IItemEvent)
Dim oForm As SAPbouiCOM.Form
Dim oMatrix As SAPbouiCOM.Matrix
Dim oDBDataSource As SAPbouiCOM.DBDataSource
Dim oConditions As New SAPbouiCOM.Conditions
Dim oCondition As SAPbouiCOM.Condition
Dim oDocNum As SAPbouiCOM.EditText
Dim lIndice As Long
Set oForm = oApplicazione.Forms.GetFormByTypeAndCount(pVal.FormType, pVal.FormTypeCount)
Set oDBDataSource = oForm.DataSources.DBDataSources.Item("MyUserTableName")
Set oMatrix = oForm.Items("MyMatrixName").Specific
oMatrix.Clear
'setting the condition object
'this is equal to the following SQL statement
'WHERE UserFieldName1 = "MyCriteria1" and UserFieldName2 = "MyCriteria2"
Set oCondition = oConditions.Add()
oCondition.BracketOpenNum = 2
oCondition.Alias = "UserFieldName1"
oCondition.Operation = co_EQUAL
oCondition.CondVal = "MyCriteria1"
oCondition.BracketCloseNum = 1
oCondition.Relationship = cr_AND
Set oCondition = oConditions.Add()
oCondition.BracketOpenNum = 1
oCondition.Alias = "UserFieldName2"
oCondition.Operation = co_EQUAL
oCondition.CondVal ="MyCriteria2"
oCondition.BracketCloseNum = 2
oDBDataSource.Query oConditions
'filling the matrix
For lIndice = 0 To oDBDataSource.Size - 1
oDBDataSource.Offset = lIndice
oMatrix.AddRow
Next lIndice
End Sub
Hi,
if you want to fill a matrix using an edittext (or other control) property, you need to add a row first. Then you can access the cells of this row. This does make sense, too. You cannot write in a row which does not exist yet. This is why you get the exception.
If you use the userdatasource.value property (as recommended by SAP), you first fill the value properties and then add a row as one would expect.
HTH Lutz Morrien
Hi !
I'va tried to do this ( Thanks Lutz in fact I had to create a row before ! )
Dim oRecordSet As SAPbobsCOM.Recordset
Dim oCentre As SAPbouiCOM.EditText
Dim oCompte As SAPbouiCOM.EditText
Dim oBudget As SAPbouiCOM.EditText
Dim oDepense As SAPbouiCOM.EditText
Dim oSolde As SAPbouiCOM.EditText
Dim i As Long
i = 1
Set oRecordSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
oRecordSet.DoQuery ("select * from [@CAP_OPRC_BUDGET]")
While oRecordSet.EOF = False
' HERE ADD A ROW TO THE MATRIX
' Addrow (number of the row to be added, number next row)
oMatrixRep.AddRow i, i + 1
' filling the matrix
Set oCentre = oMatrixRep.Columns("clCentre").Cells.Item(i).Specific
oCentre.String = oRecordSet.Fields.Item(0).Value
' SBO_Application.MessageBox (oRecordSet.Fields.Item(0).Value)
oRecordSet.MoveNext
i = i + 1
Wend
Thanks,
Romeo.
Add a comment