Run-time error '9' when calling LBound on a dynamic array

  • Thread starter Thread starter paul.schrum
  • Start date Start date
P

paul.schrum

Access 2007

I am getting a "subscript out of range" error when using LBound on a
dynamic array which I just ReDim'd.

<code>
Dim ad_aveGallonsPerDay() As Double ' ad_ stands for Array of
Doubles
ReDim da_aveGallonsPerDay(2 To 12)
Dim testLB As Long, testUB As Long
testLB = LBound(ad_aveGallonsPerDay) ' error occurs at this line
</code>

Can anyone help me figure out what I should do differently?

Thanks.
- Paul Schrum
 
Access 2007

I am getting a "subscript out of range" error when using LBound on a
dynamic array which I just ReDim'd.

<code>
Dim ad_aveGallonsPerDay() As Double ' ad_ stands for Array of
Doubles
ReDim da_aveGallonsPerDay(2 To 12)

Typo: Should be ReDim ad_aveGallonsPerDay(2 To 12)
 
On Sat, 30 Jul 2011 10:15:59 -0700 (PDT), "(e-mail address removed)"

As Stuart points out there's a typo present but to add to his reply.

(It leaped right out at me but then I've been programming for 30+
years so maybe my brain does that automatically how.)

Ensure you have Option Explicit at the top of all code modules
including forms and reports as well as VBA.

Also in the VBA editor Tools >> Options and check the Require Variable
Declaration check box. This will ensure all new forms, reports and
modules have the Option Explicit line.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/
 
Back
Top