Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    abares is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2024
    Posts
    6

    Trying to Resolve a Subscript Out of Range: Run-Time Error 9

    I am working with an "inherited" access database to produce reporting for one of my firm's annual research projects. I have used this database and the particular module represented here without issue for 7 years, but this time it is giving me a Subscript Out of Range: Run-Time Error 9. When I debug, it leads me to the code noted below, with the highlighted text noted below.

    Select Case X

    Case Is = 1 'case where both NumInJob and BaseAvg were reported
    IncCount = IncCount + SortedBaseSet("NumInJob") 'add to incumbent count
    BaseIncCount = BaseIncCount + SortedBaseSet("NumInJob") 'add to incumbent count
    WtdFactor = WtdFactor + (SortedBaseSet("BaseAvg") * SortedBaseSet("NumInJob"))
    AvgIncFactor = AvgIncFactor + 1 'One person added to track simple average
    AvgFactor = AvgFactor + SortedBaseSet("BaseAvg")
    N = N + 1
    DataTank(N) = SortedBaseSet("BaseAvg") ' read into array

    Putting my curser over the N following DataTank gives me the number 10001

    Earlier in the module, the DataTank is referenced in the following code:

    Dim DataTank(1 To 10000) As Double, C As Integer, IncCount As Integer, BaseIncCount As Integer, WtdFactor As Double

    This leads me to think there is a duplicate record in the DataTank, but I'm not sure how to find the "DataTank" among the tables and queries that the module draws on. It doesn't seem to be a common term in Access use, so I'm guessing it might just be a term the original programmer liked to use.

    I am a non-technical, but have been using Access for a number of years. Can anyone suggest an approach to help me find the data (assume its in a table somewhere - there are many in this database) that is being referenced in this "Subscript Out of Range" error?

    Many thanks for your help.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    Firstly that is an array?
    You have some how exceeded the dimensions of that array, hence the error message.
    So you need to find out why the original programmer decided 10000 was enough and now you are up to more than 10000 ?
    You could just increase the Dim line to 12000 ?, but that will probably fall over in the future when you exceed 12000?

    So you really have to discover why the increase?


    Insert
    Code:
    Debug.Print DataTank(N)
    before N = N + 1
    and then look at the output in the immediate window (Ctrl + G)

    If the 'duplicates' are not near each other, it could be tricky to see where the issue lies.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    DataTank is an array variable. Somewhere code may be opening a recordset object to feed that array. Possibly SortedBaseSet() is a recordset object. Find code that is building SortedBaseSet and will probably find reference to table data is pulled from.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    abares is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2024
    Posts
    6
    Welshgasman

    Thanks for quick response.
    Over the 7 yrs of using this and other databases, I've discovered that the original programmer created and coded in a number of limitations (size, content, etc.) that seemed completely arbitrary, made no sense given the purpose and use of the database. In looking at a couple of other databases created by the same individual, I've noticed that the coding for this module used figures (rather than the 10000) that ranged from 200 (I can't figure out why that one hasn't encountered a similar error) and 100000.

    I did insert the debug code you recommended and it gave me the number 46, which doesn't correspond to anything I can think of.

    Betting that the 10000 was an arbitrary figure, I tried increasing the Dim line to 12000 and rerunning the module, but I received the same error and this time when I put my cursor over the N following DataTank it gave me the number 12001 (as though it moved the goalpost when I changed the number). I will look at the link you provided for debugging Access (I have looked at a number - but not this one, so appreciate that).

    June7
    Thanks for your quick response. I did find the code that is building SortedBaseSet and it doesn't reference a table or query in this database. I appreciate your offer to look at the db - because it contains confidential information I am unable to share it, unfortunately.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Confidential information is why my guidance includes recommendation to make a copy and remove such data.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    abares is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2024
    Posts
    6
    I appreciate that and your clarification June7. There are many levels and a number of fields across many tables that include confidential data, and I'm not sure how we could remove or replace that information to a level that would not compromise our agreements without substantial work.

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    I'm not sure how we could remove or replace that information to a level that would not compromise our agreements without substantial work.
    Maybe this, or the other approach that is in here somewhere.

    https://www.accessforums.net/showthread.php?t=77482
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    How many tables? And how many have confidential info? What do you consider confidential? Addresses, phone, email? In copy of db, copy tables but don't copy data, delete tables with data, rename new tables.

    Is database split design?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    You only need to upload enough to see the issue. However if N was 46, then it is not the error I am thinking of?
    So walk your code and show us the EXACT line on which the error occurs. Could it occur in SortedBaseSet?

    Add Debug.Print UBound(datatank) before that line in red and report back what that shows.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    abares is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2024
    Posts
    6
    I've attempted to walk through the code as best I know how, but if I'm looking for an error beyond the line I originally noted in red font, I don't think I have sufficient understanding of Access to find it.

    I appreciate the time and attention from everyone here, but thinking now that I don't have the expertise to act appropriately on your suggestions. A business colleague has recommended a consultant with Access programming experience who can join me on a call in a few hours. At this point, I think that's a better use of everyone's time.

    I just realized that I've been sent the Cross Posting link twice now. I was clear before starting this thread that cross posting was bad form and I'm not aware that I've posted this thread anywhere else, but if I did unknowingly then I apologize for that.

    Thanks again for trying to help me.

  11. #11
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,424
    I just realized that I've been sent the Cross Posting link twice now
    That's just part of a signature. Causes this confusion sometimes so I personally would not use it. To each their own.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    The cross-posting link is in Welshgasman's signature. It shows for all of his posts. Just as the guidance in my signature shows for all posts.

    Not specific to you.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    Quote Originally Posted by abares View Post
    I just realized that I've been sent the Cross Posting link twice now. I was clear before starting this thread that cross posting was bad form and I'm not aware that I've posted this thread anywhere else, but if I did unknowingly then I apologize for that.
    So you have been sent Debugging Access link as well twice?
    As mentioned, they are links in my signature in an attempt to help newbies.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  14. #14
    abares is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2024
    Posts
    6
    Yes - clicked on the debugging articles right away the first time, and good stuff, thank you. I spent a lot of the weekend reviewing the articles and videos. Especially the Pharos video(s) which I discovered on my own before finding it in your link. Just hadn't opened the other until today.

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    Do let us know the outcome.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 02-18-2017, 05:45 AM
  2. Replies: 3
    Last Post: 01-13-2015, 05:21 PM
  3. subscript out of range error
    By adray13 in forum Import/Export Data
    Replies: 4
    Last Post: 05-24-2013, 02:26 AM
  4. Replies: 3
    Last Post: 02-01-2013, 12:26 PM
  5. Database Split - Error Subscript out of range
    By Huddle in forum Database Design
    Replies: 7
    Last Post: 07-16-2010, 01:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums