Mithyrl
Mar 29th, 2000, 01:35 AM
I am having a problem creating a Hierarchical Data Report without using a DataEnvironment.
I am able to create a simple report in the example below:
For this example you will need a form with a command button(Command1) and a DataReport with 2 rptLabels and 2 rptTextbox's (located in Detail Section1).
Also a copy of the Nwind.mdb
All code can go into the Command1_click() event
Private Sub Command1_Click()
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim j As Integer
Dim i As Integer
Dim k As Integer
Dim intCtrl As Integer
'set the connection to Nwind.mdb database
con.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb;"
'Set the .CommandText to desired SQL statement
With cmd
.ActiveConnection = con
.CommandType = adCmdText 'SQL
.CommandText = "Select FirstName,Lastname from Employees ORDER BY Lastname"
.Execute
End With
'Open the Recordset
With rs
.ActiveConnection = con
.CursorLocation = adUseClient
.Open cmd
End With
'reset counters
i = 0
j = 0
k = 0
'Populate the Data Report
With DataReport1
.Hide
Set .DataSource = rs
.DataMember = ""
With .Sections("Section1").Controls 'Detail Section of Report
For intCtrl = 1 To .Count 'loop through all controls in detail section
If TypeOf .Item(intCtrl) Is RptLabel Then
.Item(intCtrl).Caption = rs.Fields(j).Name & " :"
j = j + 1
End If
If TypeOf .Item(intCtrl) Is RptTextBox Then
.Item(intCtrl).DataMember = ""
.Item(intCtrl).DataField = rs(k).Name
k = k + 1
End If
Next intCtrl
End With
.Refresh
.Show
End With
End Sub
This creates a nice simple report with all employees First names and Last names sorted by Lastname.
My Question is Say I wanted to insert a group Header/Footer into the dataReport?
For Example I wanted a Group Header showing each of these employees grouped by what their [Title] is?
1) How would I add this group Header to the DataReport?
2) Once the Headers were added what controls should be added to the Group Header/Footer?
3) What code would have to be added to populate the newly added controls on the DataReport?
4) Any other additional coding...ie. using a SHAPE command to form the recordset to get the necessary results?
Any assistance that anyone can give me would be most appeciated. Thank you.
I am able to create a simple report in the example below:
For this example you will need a form with a command button(Command1) and a DataReport with 2 rptLabels and 2 rptTextbox's (located in Detail Section1).
Also a copy of the Nwind.mdb
All code can go into the Command1_click() event
Private Sub Command1_Click()
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim j As Integer
Dim i As Integer
Dim k As Integer
Dim intCtrl As Integer
'set the connection to Nwind.mdb database
con.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb;"
'Set the .CommandText to desired SQL statement
With cmd
.ActiveConnection = con
.CommandType = adCmdText 'SQL
.CommandText = "Select FirstName,Lastname from Employees ORDER BY Lastname"
.Execute
End With
'Open the Recordset
With rs
.ActiveConnection = con
.CursorLocation = adUseClient
.Open cmd
End With
'reset counters
i = 0
j = 0
k = 0
'Populate the Data Report
With DataReport1
.Hide
Set .DataSource = rs
.DataMember = ""
With .Sections("Section1").Controls 'Detail Section of Report
For intCtrl = 1 To .Count 'loop through all controls in detail section
If TypeOf .Item(intCtrl) Is RptLabel Then
.Item(intCtrl).Caption = rs.Fields(j).Name & " :"
j = j + 1
End If
If TypeOf .Item(intCtrl) Is RptTextBox Then
.Item(intCtrl).DataMember = ""
.Item(intCtrl).DataField = rs(k).Name
k = k + 1
End If
Next intCtrl
End With
.Refresh
.Show
End With
End Sub
This creates a nice simple report with all employees First names and Last names sorted by Lastname.
My Question is Say I wanted to insert a group Header/Footer into the dataReport?
For Example I wanted a Group Header showing each of these employees grouped by what their [Title] is?
1) How would I add this group Header to the DataReport?
2) Once the Headers were added what controls should be added to the Group Header/Footer?
3) What code would have to be added to populate the newly added controls on the DataReport?
4) Any other additional coding...ie. using a SHAPE command to form the recordset to get the necessary results?
Any assistance that anyone can give me would be most appeciated. Thank you.