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
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