I'm receiving a Run Time Error 13 - Type Mismatch - using a recordset in VBA

Posted on 2008-11-18
Last Modified: 2013-11-27
I've been running this code in another database with no problems.  I copied it to a new database and now I'm receiving Run Time Error 13 Type Mismatch at the line below.  Any ideas?

Set rstRecipient = DB.OpenRecordset(strSql, dbOpenDynaset)

Dim Maildb As Object        'The mail database

Dim UserName As String      'The current users notes name

Dim MailDbName As String    'THe current users notes mail database name

Dim MailDoc As Object       'The mail document itself

Dim AttachME As Object      'The attachment richtextfile object

Dim Session As Object       'The notes session

Dim EmbedObj As Object      'The embedded object (Attachment)

'Dim Subject As String

'Dim Attachment As String

'Dim Recipient As String

'Dim BodyText As String

Dim SaveIt As Boolean

Dim DB As DAO.Database

Dim strSql As String

Dim strRecipient As String

Dim recipient(5) As Variant

Dim rstRecipient As Recordset

Set DB = CurrentDb

'Start a session to notes

Set Session = CreateObject("Notes.NotesSession")


UserName = Session.UserName

'Attachment = strAttachment

'Recipient = strRecipient

'BodyText = strBodyText

'Subject = strSubject

SaveIt = "True"

'Next line only works with 5.x and above. Replace password with your password

'Session.Initialize ("biomerieux")


'Get the sessions username and then calculate the mail file name

'You may or may not need this as for MailDBname with some systems you

'can pass an empty string or using above password you can use other mailboxes.


MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"


'Open the mail database in notes

Set Maildb = Session.GETDATABASE("", MailDbName)

If Maildb.ISOPEN = True Then 'Already open for mail



End If

strSql = "Select * from tbl_Old_Dates_email"

Set rstRecipient = DB.OpenRecordset(strSql, dbOpenDynaset)

Open in new window

Question by:Marilync1266
    LVL 56

    Accepted Solution

    For Access 2000 and up, the default data lib is ADO, which has a recordset object and is the reason for the error.  Open the VBA Editor, click tools/references.  Unselect the ADO data lib, then scroll down and find the "Microsoft Data Access Objects lib" and check it.
     This assumes your using no ADO.  If you are, then you need both libs checked and you need to explicitily delcare the objects.  ie.
    Dim rstRecipient As DAO.Recordset

    LVL 119

    Expert Comment

    by:Rey Obrero
    change this

    Dim rstRecipient As Recordset


    Dim rstRecipient As Dao.Recordset

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now