Can someone help me with creating a data report using data from an array (2 dim)
I am not sure how I can display the data in the report. Should I be using text boxes ?
Thanks !
Printable View
Can someone help me with creating a data report using data from an array (2 dim)
I am not sure how I can display the data in the report. Should I be using text boxes ?
Thanks !
you can transform you array into an ADO recordset and assign the recordset variable to the DataSource property of your Report.
You need to manually add the controls to your data report via the data report design window and "Insert Control/Textbox".
Hey Lothar,
Could you tell me how I can transform the array? I am a beginner and am not very familiar with ADO's.
I didnt really find any material on transforming to a recordset.
Thanks !!!
here is a sample that
- fills an array
- transforms that into a recordset
- passes that rs to a datareport for display
add a textbox for each "field" (=column) in your array and set the DataField property for each textbox in your datareport to the field name in your recordset.
Dim arr(0 to 5, 0 to 10) as Integer
Dim i as Integer
Dim j as Integer
' fill array
for i = 0 to 5
for j = 0 to 10
arr(i, j) = i * j
next j
next i
' transform into rs
Dim rs as new ADODB.Recordset
for j = 0 to UBound(arr, 2)
rs.Fields.Append CStr(j), adInteger
next j
rs.Open
for i = 0 to UBound(arr, 1)
rs.AddNew
for j = 0 to UBound(arr, 2)
rs.Fields(j).Value = arr(i, j)
next j
rs.Update
next i
set r.DataSource = rs
r.Show
Thanks for the help.
But i am getting an error saying that ' the application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another '.
The data is going into the array fine.
But code stops here: vbcode reportrs.Fields.Append l, adVarChar /vbcode
I'm not sure what I am doing wrong !
Here is the code used:
vbcode
Dim arr(0 to 200, 0 to 40) as string
Dim i, j, k, l As Integer
Dim rsReport As Recordset
' To store values of the flex grid to an array
k = 1
For i = 0 To MSFlexGrid1.Rows - 1
If (MSFlexGrid1.RowHeight(i) > 1) Then
l = 1
For j = 0 To MSFlexGrid1.Cols - 1
If (MSFlexGrid1.ColWidth(j) > 1) Then
arr(k, l) = MSFlexGrid1.TextMatrix(i, j)
'MsgBox Me.MSFlexGrid1.TextMatrix(i, j)
'MsgBox arr(k, l)
l = l + 1
End If
Next j
k = k + 1
End If
Next i
' Transform the array into a recordset
Dim reportrs As New ADODB.Recordset
For l = 0 To UBound(arr, 2)
reportrs.Fields.Append l, adVarChar
Next l
reportrs.Open
For k = 0 To UBound(arr, 1)
reportrs.AddNew
For l = 0 To UBound(arr, 2)
reportrs.Fields(l).Value = arr(k, l)
Next l
reportrs.Update
Next k
Set RptBudgets.DataSource = reportrs
' Open Report
RptBudgets.Show
/vbcode
Got it !
Shd have used adbstr instead of advarchar
I have the report opening up now .
But I'm having problems in setting the datafield property for the text boxes.
>But I'm having problems in setting the datafield property for the text boxes.
what kind of "problems"?
you just open the report window, right-click and select "Insert Control"/TextBox from the context menu.
Then go to the properties window and enter the data field name.
Well, For example, I am setting the datafield of one of the textboxes in the report to be:
[vbcode ] rsreport.Fields.Item(0) [/vbcode]
This gives me an error saying datafield not found.
Also, I want the report to have a heading with the name, which may be different at different instances. Do you have any idea how i can pass the variable to the report ? I am trying to pass the variable through code but doesnt seem to work !
Is there a book or website you refer for data reports? I havent found much material anywhere and dont want to keep bugging you with simple questions :-)
>rsreport.Fields.Item(0)
this not a legal VB statement.
What I meant was: set the DataField Property of the Textbox in the properties Toolbox of the datareport designer window to the name of your field.
It's kind of hard to explain, when all you have is an ASCII text editor, isn't it?
>Also, I want the report to have a heading with the name, which may be different at different instances. Do you have any idea how i can pass the variable to the report ?
you can assign the heading at runtime via the object model of the datareport.
DataReport1.Sections(1).Controls.Item("heading").Caption = "header"
I have added a Label control to the heading section of the report.
>s there a book or website you refer for data reports?
None that I know of.