3

I started getting error 3048 - Can't open more databases. I seem to have tamed it by implementing a single, static database variable in a function "dbLocal()" after David Fenton's example here.

I would still like to monitor the number of database references to see how close I am getting to the 2048 limit in Access. I have tried to use .Recordsets.Count but it always returns zero. How can I determine the reference/recordset count being used internally by Access?

One place I've tried to look at it is in the "dbLocal()" function. Stripped down to less-than-bare-minimum here (in my code I use Fenton's full example), I'm trying this:

Public Function dbLocal() As DAO.Database

    Static dbCurrent As DAO.Database

    If dbCurrent Is Nothing Then
        Set dbCurrent = CurrentDb()
    End If
    Set CurDb = dbCurrent
    Debug.Print dbCurrent.Recordsets.Count

End Function

but it always prints zero. Even if it worked, it's not what I really want, because (if I am understanding correctly) Access is maintaining its own accounting that includes references due to queries, combo-boxes, etc., whereas my static variable would only "know about" references due to VBA statements explicitly using this dbLocal() function.

Is there a way to get a peek at Access' internal accounting to know how close I might be to exhausting the 2048 maximum?

In case it matters: Windows XP Pro SP3; Access 2010 32-bit version 14.0.6024.1000 SP1 MSO 14.0.6112.5000.

3
  • Sadly, you won't get an answer from David W. Fenton as he passed away last month :(
    – onedaywhen
    Dec 19, 2011 at 8:28
  • @onedaywhen That is sad. I wondered why he was not around. Do you know if there is a remembrance page?
    – Fionnuala
    Dec 19, 2011 at 11:27
  • @Remou: me too and I found this and this. I will genuinely miss him.
    – onedaywhen
    Dec 19, 2011 at 11:33

1 Answer 1

1

One way to do it is to just keep opening recordsets until you get an error:

Function TablesAvailable() As Integer
Dim i As Integer, rs As DAO.Recordset, rsColl As Collection

    On Error GoTo Err_TablesAvailable

    Set rsColl = New Collection
    Do While i < 4096
        i = i + 1
        Set rs = CurrentDb.OpenRecordset("SELECT 1")
        rsColl.Add rs
    Loop

Exit_TablesAvailable:
    For Each rs In rsColl
        rs.Close
        Set rs = Nothing
    Next rs
    Exit Function
Err_TablesAvailable:
    Select Case Err.Number
    Case 3048 'Cannot open any more databases.
        TablesAvailable = i
    Case Else
        MsgBox Err.Number & ": " & Err.Description
    End Select
    Resume Exit_TablesAvailable
End Function
8
  • I'll give this a try now. Needless to say, I'm curious as to whether/how .Recordsets.Count (or some direct equivalent) can be made to work (because there ought to be a way!), but I like your out-of-the-box approach and it should give me the insight I began looking for as to how close I am to bumping my head on the ceiling. Thanks!
    – GISmatters
    Nov 28, 2011 at 17:15
  • This code seems to work, although running it on a new, blank database (no tables, queries, or forms... just a module with this function in it, running the function from the immediate window) says only 252 unused references/recordsets. I get the same number in my current app before opening any forms. Can this number be correct? I have seen 2048 given as the maximum available in recent versions of Access; apparently 1024 in older versions. Can Access be consuming almost 1800 of them before even opening a form?!
    – GISmatters
    Nov 28, 2011 at 18:53
  • I did the same as you and got similar results. And had the same thought. It makes me wonder if the real number should actually be 256 as opposed to 2048/1096. Do you remember where you saw that the limit was 2048? I could not find it in any Microsoft documentation.
    – mwolfe02
    Nov 28, 2011 at 19:34
  • 1
    For example: here and here and others from this Google search
    – GISmatters
    Nov 28, 2011 at 20:16
  • I'm led to the same conclusion as you, though I hate to leave things to supposition... hopefully someone will weigh in here sooner or later with some more definitive info. In the meantime, I'm going to suppose that whatever the 2048 limit is, as a practical matter I've got more like 256 to work with. Using your function, by the time my app is running - a main form with many controls and sub-forms - I've only got 40 unused slots remaining, and I've seen that go as low as mid-twenties if I open additional forms. I guess if the limit is ~250, then I've still got ~10% left?! Better than Err3048...
    – GISmatters
    Nov 28, 2011 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.