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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subscript Out of Range

Status
Not open for further replies.

tsdp

Programmer
Jul 17, 2001
6
US
Crystal - Version 8.5
VB - Version 6.0

Can anyone tell me why I get a subscript out of range error everytime I try to set the data source in vb to a report created using the designer with unbound fields. I have the exact number of fields in the report that the table contains. The datatype has been double checked and it is the same. I even put them onto the report in the exact order as the SQL SELECT statement. Confused??

rsData is a ADODB.Recordset - the SQL statement works fine
With rsData
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.Source = strSQL
.ActiveConnection = cnnTest
.Open
.ActiveConnection = Nothing
End With

Report.Database.SetDataSource rsData, 3, 1
"WILL NOT GO PAST THIS LINE OF CODE"

Report.AutoSetUnboundFieldSource crBMTNameAndValue

Load CRViewer1
CRViewer1.Show
 
Why are you doing this before you pass the recordset to the report?

.ActiveConnection = Nothing Brian J. Alves
Email: brian.alves@worldnet.att.net
VB / ASP / Crystal / SQLServer
 
I am done with the connection, I use it just to run my sql statement and set it to a recordset. I then want to pass the recordset that is in memory to the report.
 
It would just seem safer to leave the ADO connection active until after you create the report.

Why not set each unbound field with .SetUnboundFieldSource and see if/which field is the problem? Brian J. Alves
Email: brian.alves@worldnet.att.net
VB / ASP / Crystal / SQLServer
 
I tried leaving the connection open, still received the subscript out of range. I also tried setting each field manually, same error. I just don't get it.
 
What type of data source did you select when you created the report? More Data Sources / Active Data? Brian J. Alves
Email: brian.alves@worldnet.att.net
VB / ASP / Crystal / SQLServer
 
I am not connecting to a data source at all through crystal. I want to use unbound fields then bind them at runtime. According to the Crystal Reports 8 "The Complete Reference" I shouldn't have to directly connect to the source with my report. I have upgraded to 8.5 so I'm not for sure if anything has changed. Of course the 8.5 User Guide that came with is of little use.
 
I get this too. I'm pulling in a recordset from a single .dbf file, using the Advantage Server OLEDB driver. (Not that that should matter once the recordset is there.) Then I'm just trying to assign the adodb recordset to the datasource. The report has 4 unbound and properly named fields, and the program stops at the datasource assignment before getting to the setunboundfieldsource statements. What subscript exactly is it referring to?!
 
I have been pulling my hair out over this one, and have posted everywhere. It would seem to me that if everyone is having the same problem, somebody would have figured out the answer.

 
I haven't done much with unbound fields but it appears that the problem has to do with the fact the CR is trying to set the data source to a NEW value, when it can't find an existing data source (ie, the table index (subscript) of 1 is out of range).

I think you might need to create the report against an initial TTX file that has the recordset field names in it, or else the SetDataSource can't function. This seems to defeat the purpose of having unbound fields, so I might have missed something.

The commands all worked fine if I used them with a report made with a TTX, but I couldn't do anything with a blank report that simply had all unbound fields. Hope this helps. Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
This is happening because there are no Tables in the Crystal Report's Tables Collection. You are correct that you do not have to connect to any datasource with the report. For example, you can build an ADO disconnected recordset and use this as the data source for the report. You just have to make sure that you add a table to the report's tables collection first and set the connection info parameter to the recordset (rs):

crReport.Database.Tables.Add "", ,rs, ,"p2smon.dll"

The Add method takes 3 parameters:

1. data - Data Source for report

2. data tag - 3 is the only thing you can supply

3. data number - * Here is the problem. The add method expects there to be at least one item (1 table) in the tables collection.

After you add the table to the tables collection you can now use the SetDataSource method:

crReport.Database.SetDataSource rs, 3, 1
 
Oops in my first post for this I said the third paramter to the add method is data number - it is table number. Sorry for the typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top