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!

Binding Unbound Fields To a DataSource

Status
Not open for further replies.

Craiger

Programmer
May 24, 2001
4
US
I am having trouble binding my ado recordset to my report that I designed in the Crystal Report 8 design from within Visual Basic 6.0. The report "crUnboundFields" contains a report with 6 unboundstring fields.

My recordsetset contains 6 fields. While debugging I can dump out my data fine using the VB debugger. However, prior to assigning my unboundfields, I get a runtime error 9, Subscript out of range error.

I have never used unboundfields before. I have frequently used the setDatasource method successfully with bound fields.

If anyone can give me any help I would really appreciate it.

Thanks

Craig Adams


dim RptAttributeRpt as crUnboundFields
Set RptAttributeRpt = New crUnboundFields

The following line produces a "Runtime Error 9 Subscript out of Range" error.
RptAttributeRpt.Database.SetDataSource Rs,3

'Program errors before getting to this line.
'Binding to recordset fields happen here
RptAttributeRpt.Field1.SetUnboundFieldSource "{ado.ID"}"
......

 
put this code in your form.
hope this helps


Dim URpt As New UsabilityRpt
Dim ADOrs As Adodb.Recordset
Dim ADOcn As New Adodb.Connection
Dim rs As rdoResultset

Dim ADOrs As New Adodb.Recordset
'Set connection to data base

On Error GoTo stperr:


With ADOcn
'DBChange
.ConnectionString = "dsn=dsnname;uid=userid;pwd=password"
.CursorLocation = adUseClient 'adUseServer 'Server Side Is Faster
.Open
End With

sSql = "select * from table"

ADOrs.Open sSql, ADOcn, adOpenForwardOnly, adLockPessimistic

URpt.Database.AddADOCommand ADOrs.ActiveConnection, ADOrs.ActiveCommand
'Set Report to DataBase

If ADOrs.EOF Then ' Check to see if there is information
Set URpt = Nothing
ADOcn.Close
MsgBox "no data", vbOKOnly + vbExclamation, "Retrieving Error"
CmdClose_Click
Exit Sub

Else

With URpt

'Set fields in data base equal to report fields

.UnboundString1.SetUnboundFieldSource "{ado.fieldname1}"
.UnboundString3.SetUnboundFieldSource "{ado.fieldname2}"
.UnboundString2.SetUnboundFieldSource "{ado.fieldname3}"
.UnboundString4.SetUnboundFieldSource "{ado.fieldname4}"
.UnboundNumber1.SetUnboundFieldSource "{ado.fieldname5}"

End With

End If

CRViewer1.Visible = True
cmdClose.Visible = True

CRViewer1.ReportSource = URpt
MousePointer = vbDefault
CRViewer1.EnableGroupTree = False
CRViewer1.EnableRefreshButton = False
CRViewer1.EnableCloseButton = False
' CRViewer1.EnableExportButton = True

CRViewer1.Top = 200
CRViewer1.Left = 150
CRViewer1.Height = 7300
CRViewer1.Width = 11500
CRViewer1.Zoom 1
CRViewer1.ViewReport
DoEvents

ADOcn.Close
 
Thanks mbpiper for your suggestion but I did try the add AddADOCommand and it failed with a different error.

I sent a support email request to crystaldecisions and they advised me to use a .ttx file bound to a report. They indicated that using unbound fields were not stable. I am using win2000 Professional.

After binding to a .ttx file and then overwriting the ttx file at run time seems like a very effective work around.

Thanks for you suggestion!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top