Error 3048?? Why???

User avatar
Abraxus
3StarLounger
Posts: 218
Joined: 01 Mar 2010, 17:34
Location: Blue Springs, MO

Error 3048?? Why???

Post by Abraxus »

I have code that gets email addresses out of a company directory using a corporate ID.

Today I've started getting error 3048 "Cannot open any more databases" but I don't know why. Happens at about 22/23 calls to this function

Any ideas?

Code: Select all

Function GetEmailAddress(strIn As String) As String
    Dim db As DAO.Database
    Set db = CurrentDb
    Dim rst As DAO.Recordset
    Dim strSQL As String
    strSQL = "SELECT * FROM EmployeeListing WHERE [Corporate ID] = '" & strIn & "' OR [Employee ID] = '" & strIn & "'"
    Set rst = db.OpenRecordset(strSQL, dbOpenForwardOnly)
    If rst.EOF And rst.BOF Then
        'Nothing Found
        GetEmailAddress "NONE"
    Else
        GetEmailAddress = rst![Email Address (Work)]
    End If
    rst.Close
    Set rst = Nothing
    Set db = Nothing
    
End Function
Morgan

User avatar
HansV
Administrator
Posts: 69412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Error 3048?? Why???

Post by HansV »

Does this work better?

Code: Select all

Function GetEmailAddress(strIn As String) As String
    GetEmailAddress = Nz(DLookup("[Email Address (Work)]", "EmployeeListing", _
        "[Corporate ID] = '" & strIn & "' OR [Employee ID] = '" & strIn & "'"), "NONE")
End Function
Regards,
Hans

User avatar
Abraxus
3StarLounger
Posts: 218
Joined: 01 Mar 2010, 17:34
Location: Blue Springs, MO

Re: Error 3048?? Why???

Post by Abraxus »

It did, thank you!

Now I need to learn about that DLookup!
Morgan

User avatar
HansV
Administrator
Posts: 69412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Error 3048?? Why???

Post by HansV »

Regards,
Hans