type mismatch with OpenRecordset

J

Jasper

I am trying to create a recordset using the following portion of code. I get
a type mismatch error on the "Set MyRS=" line. The code works fine in a test
database I created but I get the error in the database that I need. Any help
would be much appreciated.

Option Compare Database
Option Explicit

Sub SendMessages(Optional AttachmentPath)

Dim MyDB As Database
Dim MyRS As Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim TheAddress As String

Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("tblCitations")
MyRS.MoveFirst
 
A

Andi Mayer

I am trying to create a recordset using the following portion of code. I get
a type mismatch error on the "Set MyRS=" line. The code works fine in a test
database I created but I get the error in the database that I need. Any help
would be much appreciated.

Option Compare Database
Option Explicit

Sub SendMessages(Optional AttachmentPath)

I assume that you are using DAO and your Accessversion is 2000 or 2002

Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim MyDB As Database
Dim MyRS As Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim TheAddress As String

Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("tblCitations")
MyRS.MoveFirst

If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW
 
N

Nikos Yannacopoulos

Jasper,

CurrentDb is a DAO object, therefore your recordset should be declared
as such as well:

Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset

With this change it should work.

HTH,
Nikos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top