Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 3048: Cannot Open Any More Databases 2

Status
Not open for further replies.

DevelopV

Technical User
Mar 16, 2012
113
0
0
ZA
I am using Access 2010

I am suddenly getting the error 3048: Cannot open any more databases

The error occurs on the line of code: Set db = CurrentDb()

Code:
Private Sub SetInUseFalse(TelesalesId As Long)
  
  Dim db As DAO.Database
  Dim rst As DAO.Recordset
  
  Set db = CurrentDb()
  Set rst = db.OpenRecordset("Select InUseBy from tblTelesales where Telesalesid = " & TelesalesId)
  
  Run Some Code
  
  CloseRecordSet rst
  SetObjectToNothing db
End Sub
I always open recordsets as coded above, and close them as coded below.

Code:
 Public Sub CloseRecordSet(RecordsetName)
  
  On Error GoTo Err_Handler
  
  If Not RecordsetName Is Nothing Then
      RecordsetName.Close
      Set RecordsetName = Nothing
      GoTo Exit_Sub
  End If
  
  Exit_Sub:
      Exit Sub
  
  Err_Handler:
      Select Case Err.Number
          Case 0
              Resume Exit_Sub
                  
          Case 3420
              Resume Exit_Sub
          
          Case Else
              MsgBox Err.Number & " - " & Err.Description
              Resume Exit_Sub
      End Select
      
  End Sub
Code:
Public Sub SetObjectToNothing(ObjectName)
  
  On Error GoTo Err_Handler
  
  If Not ObjectName Is Nothing Then
      Set ObjectName = Nothing
  End If
  
  Exit_Sub:
      Exit Sub
  
  Err_Handler:
      Select Case Err.Number
          Case 0
              Resume Exit_Sub
                  
          Case 9126
              Resume Exit_Sub
          
          Case Else
              MsgBox Err.Number & " - " & Err.Description
              Resume Exit_Sub
      End Select
  
  End Sub
Why should I suddenly get this error? The error appears to be in a loop. If I close the error message, it pops up again. I have to close the database using Windows Task Manager.

Is there a maximum number of connections? But I religiously close connections as indicated above!
I am only connecting to the current database (backend form frontend)
Am I opening / closing connections & recordsets correctly?
 
How are you using SetInUseFalse()? Is this in a recordset, query, or similar that the function is being called over and over and over?

Have you considered creating a global DAO.Database object?

Duane
Hook'D on Access
MS Access MVP
 
On the form I have a command button that closes the form.
In the code I have: SetInUseFalse Me.TelesalesId

How would I create a global DAO.Database object?
How would it help?
Sorry, but I don't anything about global objects!
 
Found the problem!
I had an endless loop in my code
Code:
Private Sub SetInUseFalse(TelesalesId As Long)

Dim db As DAO.Database
Dim rst As DAO.Recordset

If IsNull(TelesalesId) Then Exit Sub

Set db = CurrentDb()
Set rst = db.OpenRecordset("Select InUseBy from tblTelesales where Telesalesid = " & TelesalesId)
If rst.RecordCount > 0 Then
     If rst!InUseBy = pubUserID Then
         SetInUseFalse TelesalesId  <===========
     End If
End If

CloseRecordSet rst
SetObjectToNothing db

End Sub
I have marked the error with <===========

Thanks to all how helped
 
DevelopV,
You should be clicking the "Like this post? Star it!" on the reply from strongm. This gives him/her some credit and suggests the thread is closed :)

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top