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 strongm 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» error....

Status
Not open for further replies.

Aietoe

Technical User
Nov 30, 2000
85
CA
I,

Using Acces97 i'm trying to reset the page number to 1 on a group break.

Here is my code:


Option Compare Database
Option Explicit
Dim GrpArrayPage(), GrpArrayPages()
Dim GrpNameCurrent As Variant, GrpNamePrevious As Variant
Dim GrpPage As Integer, GrpPages As Integer

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

End Sub

Private Sub PageFooter_Format(Cancel As Integer, FormatCount As Integer)
Dim i As Integer
If Me.Pages = 0 Then
ReDim Preserve GrpArrayPage(Me.Page + 1)
ReDim Preserve GrpArrayPages(Me.Page + 1)
GrpNameCurrent = Me!Client
If GrpNameCurrent = GrpNamePrevious Then
GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1
GrpPages = GrpArrayPage(Me.Page)
For i = Me.Page - ((GrpPages) - 1) To Me.Page
GrpArrayPages(i) = GrpPages
Next i
Else
GrpPage = 1
GrpArrayPage(Me.Page) = GrpPage
GrpArrayPages(Me.Page) = GrpPage
End If
Else
Me!ctlGrpPages = "Group Page " & GrpArrayPage(Me.Page) & " of " & GrpArrayPages(Me.Page)
End If
GrpNamePrevious = GrpNameCurrent

End Sub




I have placed a control «ctlGrpPages» in the page footer.

I've created a text box with the following control source ="Page " & [Page] & " of " & [Pages] in the group footer.


I still get an error saying "Subscript out of range" !!? The error seems to be coming from the 3rd to last line of code (is has changed to yellow) that reads:

Me!ctlGrpPages = "Group Page " & GrpArrayPage(Me.Page) & " of " & GrpArrayPages(Me.Page)

Hints:
1)The controltip changes to the message :
&quot;GrpArraypage(Me.Page)=<subscript out of range>&quot; when i move it over the words &quot;GrgArrayPage&quot; in the 3rd tl last line of code

2)The control tip shows that the value of (Me.Pages) as &quot;Me.Page=2&quot;


Help me please, i'm getting quite frustrated.


Thanks in advance.

Aietoe
 
Hi Aietoe!

Well you are dimensioning the arrays in the Then portion of the If statement and the line in question is using the arrays in the Else portion. Therefore, the arrays haven't been correctly dimensioned and that is why the subscript is out of range.

hth


Jeff Bridgham
bridgham@purdue.edu
 
Hi Jebry,

I have tried to change my proc to :

Private Sub PageFooter_Format(Cancel As Integer, FormatCount As Integer)
Dim i As Integer
ReDim Preserve GrpArrayPage(Me.Page + 1)
ReDim Preserve GrpArrayPages(Me.Page + 1)

If Me.Pages = 0 Then
GrpNameCurrent = Me!Bénef
If GrpNameCurrent = GrpNamePrevious Then
GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1
GrpPages = GrpArrayPage(Me.Page)
For i = Me.Page - ((GrpPages) - 1) To Me.Page
GrpArrayPages(i) = GrpPages
Next i
Else
GrpPage = 1
GrpArrayPage(Me.Page) = GrpPage
GrpArrayPages(Me.Page) = GrpPage
End If
Else
Me!ctlGrpPages = &quot;Group Page &quot; & GrpArrayPage(Me.Page) & &quot; of &quot; & GrpArrayPages(Me.Page)
End If
GrpNamePrevious = GrpNameCurrent

End Sub


And now, i get Group page 1 of x to x of x for my first group, but my second group generates &quot;Blanks&quot; - «GROUP PAGE OF »[

I guess i made a wrong move.
Could you just give me a final hint on where to put those dim..


Thanks

Aietoe!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top