Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim rs1 As New ADODB.Recordset
Private Sub Command1_Click()
Dim q As Integer
Dim intCtrl As Integer
Dim x As Integer
Dim z As Integer
x = 0
q = 0
z = 0
With DataReport1
.Hide
Set .DataSource = rs
.DataMember = ""
With .Sections("section4").Controls
For intCtrl = 1 To .Count
If TypeOf .Item(intCtrl) Is RptLabel Then
.Item(intCtrl).Caption = "City" & " :"
q = q + 1
End If
If TypeOf .Item(intCtrl) Is RptTextBox Then
.Item(intCtrl).DataMember = ""
.Item(intCtrl).DataField = "City"
End If
Next
End With
q = 0
With .Sections("Section1").Controls
For intCtrl = 1 To .Count
If TypeOf .Item(intCtrl) Is RptLabel Then
.Item(intCtrl).Caption = rs1.Fields(q).Name & " :"
q = q + 1
End If
If TypeOf .Item(intCtrl) Is RptTextBox Then
.Item(intCtrl).DataMember = "Command1"
.Item(intCtrl).DataField = rs1(z).Name
z = z + 1
End If
Next intCtrl
End With
.Refresh
.Show
End With
End Sub
Private Sub Form_Load()
Command1.Caption = "Show Report"
cn.Open "Provider=MSDATASHAPE; Data Provider=Microsoft.JET.OLEDB.4.0;" & _
"Data Source=D:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb;"
With cmd
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = " SHAPE {SELECT FirstName,Lastname,City FROM `Employees`} AS Command1 COMPUTE Command1 BY 'City'"
.Execute
End With
With rs
.ActiveConnection = cn
.CursorLocation = adUseClient
.Open cmd
End With
Set rs1 = rs(0).Value
End Sub