Pulling my hair out!
I am trying to inport Outlook 2007 Contact list into Access 2007 table. Running debug, the code stops at the RED text rs("olfirstname") = .FirstName. I get this error message "Invalid or unqualified reference". I find a lot of Access contacts to Outlook on the forum but not the other way around.
Can anybody show me what I am doing wrong?
Thanks for the help,
Richard
Can anybody show me what I am doing wrong?
Thanks for the help,
Richard
Code:
Function OLContactList()
Dim ol As Object
Dim olns As Object
Dim objFolder As Object
Dim objAllContacts As Object
Dim db As Database, rs As Recordset
Dim Contact As Object
'set up database to receive tasks
Set db = CurrentDb
Set rs = db.OpenRecordset("tblOLContacts", DB_OPEN_DYNASET)
' Set the Application object.
Set ol = Outlook.Application
' Set the Namespace object.
Set olns = ol.GetNamespace("MAPI")
' Set the default Contact folder.
Set objFolder = olns.GetDefaultFolder(olFolderContacts)
' Set objAllContacts equal to the collection of all Contacts.
Set objAllContacts = objFolder.Items
' Loop through each Contact.
For Each Contact In objAllContacts
'adds to table
rs.AddNew
[COLOR=red]rs("olfirstname") = .FirstName[/COLOR]
rs("ollastname") = .LastName
rs.Update
Next
Set rs = Nothing
Set db = Nothing
End Function