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 SkipVought 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.

kab555

Programmer
Jan 18, 2002
46
0
0
US
Hi,
I'm using VB6 with Crystal Reports 8.5. I have a list of options buttons in a form that will sort the report in various ways. I did some work in this project, and now I am getting a "Subscript out of range". It has something to do with my sorting options, but I'm out of ideas as to fixing it. I have gone so far as to delete all the code, along with the buttons, and re-add everything back in, but the error still persists. Can anyone point me in the right direction?

By the way, I'm self taught in VB6, and am a novice, which doesn't help the situation.

Thanks!
Kristie
 
This is generally an array problem - have you dimensioned an array then tried to reference outside the dimmed size?

eg
Dim myArray(10) as String

Then doing myArray(12) = text
will give error 9 "Subscript out of range"

For further details see:

To get more help, see FAQ below - we may need to see your declarations and the code where the error arises.
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Did you use a control array of Option Buttons? If you are trying to reference this array, and use a index that is beyond what you have in the array, then you will get this error. Remember that control arrays default to 0 base, so for example if you have 5 option buttons, they will default to Option(0) through Option(4). Trying to use option(5) would give the "subscript out of range" error.

If this does not help, post the code where the error occurs.

Robert
 
Here is the code. I haven't used control arrays, yet.

This is the code that finds what the user selected for the option

'The following statments determine the sort order of the report
If InsOpt.Value Then
Set IndPaySort = IndPyRpt.Database.Tables.Item(1).Fields.Item(4)
End If 'Sorts by Claim Insured

If ClmantOpt.Value Then
Set IndPaySort = IndPyRpt.Database.Tables.Item(1).Fields.Item(3)
End If 'Sorts by Claimant Name

If PaidDtOpt.Value Then
Set IndPaySort = IndPyRpt.Database.Tables.Item(1).Fields.Item(9)
End If 'Sorts by Paid Date

If LobOpt.Value Then
Set IndPaySort = IndPyRpt.Database.Tables.Item(1).Fields.Item(7)
End If 'Sorts by LOB

If RptOpt.Value Then
Set IndPaySort = IndPyRpt.Database.Tables.Item(1).Fields.Item(5)
End If 'sorts by Report Date

If ClmNumOpt.Value Then
Set IndPaySort = IndPyRpt.Database.Tables.Item(1).Fields.Item(12)
End If 'Sorts by the last four digits of the Claim Number
'End of Sorting Options

This is the code piece where the program breaks

IndPyRpt.RecordSortFields.Item(1).Field = IndPaySort
 
Put a breakpoint in your code on this line:
IndPyRpt.RecordSortFields.Item(1).Field = IndPaySort
Then type into Immediate window:
?IndPyRpt.RecordSortFields.Items.Count
Then hit return and see what comes up

My guess is that the answer is 1, and so it's index will probably be 0
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Johnwm,
I did what you suggested, and it gave me a 0.

Thanks for trying,
Kristie
 
If count is 0, then the collection doesn't exist. Just highlight then rightclick on the item:
IndPyRpt.RecordSortFields.Item(1).Field
and select the Definition item. That will show you where the item originates. You can usually work out what's wrong from there.
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top