Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Report Binding Syntax Help

Status
Not open for further replies.

jaycast

Programmer
Nov 28, 2001
42
US
I'm trying to bind the controls of my data report to the corresponding fields in a recordset that I have created in a coded SQL Statement. I can't seem to get the syntax down right. I have the following:

rst2.Open SQLP, SQL, adOpenKeyset, adLockReadOnly

Load DataReport2
Set DataReport2.DataSource = rst2
With DataReport2
.Sections(1).Controls("txtDescription") = rst2![ChargeCode]
End With
DataReport2.Show


But I get the following error each time:
Run-time error '3265'

Item cannot be found in the collection corresponding to the requested name or ordinal.


How should the syntax be properly written so I can get this report up and running?

Thanks in advance.
 
Ok, I've found the MS Article on this problem:

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


Now, can anyone explain what exactly they are doing. I'm trying hard to decipher the generic code and apply it to my custom solution, but it doesn't seem to be working. The way I read the code, it is dynamically placing the values in the fields depending on the field order in the SQL statement. If that's the case, I can't have that. I need to bind the fields in a particular order.

Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top