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

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
 
S

Stuart McCall

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)
 
T

Tony Toews

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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top