Referencing a query in CurrentDB

G

GL

Hi,
I initially set this up (with a little help) to look at a
query in another db and it worked fine, but now I want to
change it to look at a query in the db thats open, but it
doesn't work! I get a debug Type Mismatch on the set rst
= mydb.openrecordset("qryAC") - can somebody please tell
me what I'm doing wrong. I'm guessing its something
simple because my knowledge here is limited. THANKS!
GL

Sub ExportAccessContactsToOutlook()
'Set up Objects
Dim MyDB As Database
Dim rst As Recordset
Set MyDB = CurrentDb
Set rst = MyDB.OpenRecordset("qryAC")

'Used the following when using DAO dbase and it worked
'Dim ODataBase As DAO.Database
'Dim rst As DAO.Recordset
'Set ODataBase = OpenDatabase("c:\Client
Systems\YMCA\Test")
'Set rst = ODataBase.OpenRecordset("qryOutlook")

'Set up Outlook Objects.
Dim ol As New Outlook.Application
Dim olns As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim cfsub As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
Dim Prop As Outlook.UserProperty

Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderContacts)
Set cfsub = cf.Folders.Item("Test")


With rst
.MoveFirst
'Loop through the records.
Do While Not .EOF

' Create a New Contact item.
Set c = cfsub.Items.Add


'specify which outlook form to use
c.MessageClass = "IPM.Contact"

'create all built-in Outlook fields
If ![ContactName] <> " " Then c.FullName = !
[ContactName]
If ! <> " " Then c.Email1Address = ![Email]



c.Save
' c.Close

.MoveNext
Loop
End With

End Sub
 
J

Jonathan

-----Original Message-----
Hi,
I initially set this up (with a little help) to look at a
query in another db and it worked fine, but now I want to
change it to look at a query in the db thats open, but it
doesn't work! I get a debug Type Mismatch on the set rst
= mydb.openrecordset("qryAC") - can somebody please tell
me what I'm doing wrong. I'm guessing its something
simple because my knowledge here is limited. THANKS!
GL

Sub ExportAccessContactsToOutlook()
'Set up Objects
Dim MyDB As Database
Dim rst As Recordset
Set MyDB = CurrentDb
Set rst = MyDB.OpenRecordset("qryAC")

'Used the following when using DAO dbase and it worked
'Dim ODataBase As DAO.Database
'Dim rst As DAO.Recordset
'Set ODataBase = OpenDatabase("c:\Client
Systems\YMCA\Test")
'Set rst = ODataBase.OpenRecordset("qryOutlook")
Hi GL,

I'm only guessing here but I notice that in the example
that works you explicitly reference the dao library. If
you are using Access v2000 or later then the default
library is ado. Use >>tools>>references if required to
reference the dao library - also uncheck the reference to
ado.

Dim MyDB As dao.Database
Dim rst As dao.Recordset

Luck
Jonathan
 

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