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

Discussion in 'Microsoft Access Form Coding' started by paul.schrum@gmail.com, Jul 30, 2011.

  1. Guest

    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
     
    , Jul 30, 2011
    #1
    1. Advertisements

  2. <> wrote in message
    news:...
    > 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)

    > 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
    >
     
    Stuart McCall, Jul 30, 2011
    #2
    1. Advertisements

  3. Tony Toews Guest

    On Sat, 30 Jul 2011 10:15:59 -0700 (PDT), ""
    <> wrote:

    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/
     
    Tony Toews, Jul 31, 2011
    #3
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Noor

    Dynamic Controls Array

    Noor, Sep 13, 2003, in forum: Microsoft Access Form Coding
    Replies:
    4
    Views:
    551
    HSalim
    Sep 15, 2003
  2. Wayne Pearson

    DoCmd.Quit, Dynamic Array, Form_Unload, Variable Cleanup

    Wayne Pearson, Mar 16, 2004, in forum: Microsoft Access Form Coding
    Replies:
    3
    Views:
    184
    Douglas J. Steele
    Mar 17, 2004
  3. Savvoulidis Iordanis

    Calling DoCmd.RunCommand acCmdSaveRecord, after calling an API function

    Savvoulidis Iordanis, Mar 14, 2005, in forum: Microsoft Access Form Coding
    Replies:
    2
    Views:
    593
    Savvoulidis Iordanis
    Mar 19, 2005
  4. Warrio

    Dynamic array

    Warrio, May 31, 2005, in forum: Microsoft Access Form Coding
    Replies:
    4
    Views:
    184
    Warrio
    May 31, 2005
  5. Guest

    Run Time Error when calling Function

    Guest, Nov 10, 2005, in forum: Microsoft Access Form Coding
    Replies:
    3
    Views:
    209
    Guest
    Nov 10, 2005
Loading...

Share This Page