importing from MS Outlook

  • Thread starter Kevin with VBA question for importing from MS Oult
  • Start date
K

Kevin with VBA question for importing from MS Oult

I have been importing contact names to MS Access from MS
Outlook with no problem except I want to use a string
variable to retrieve a value from a MS Outlook contact
item property (with the same name as the variable) and I
am getting a syntax error. Here is the abbreviated code I
am using:

Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderContacts)
Set objItems = cf.Items
strfld = "FullName"
' get first item in MS Outlook Contact folders
Set c = objItems.getfirst
strName = c(strfld) ' gives me a syntax error

Can anyone tell me what I am doing wrong. Would be
greatly appreciated.

Thanks,

Kevin
 
T

TC

How are you declaring c?

TC


"Kevin with VBA question for importing from MS Oultlook"
 
K

Kevin

Here are my declarations:

Dim ol As New Outlook.Application
Dim olns As Outlook.Namespace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim strfld As String
Dim strto As String
Dim test As String
Dim strName As String

c.FullName 'works fine c.anyvalideproperty works fine

Can't substitute the literal value (FullName) with a
string variable. The idea of course is to have a table of
all the contact properties I want to import instead of
having to write out all this stuff (e.g. c.FirstName,
C.LastName, C.businessAddress) in the code.

Someone on the MS Outlook forum told me this was
impossible with MS Outlook 2000.
 
T

TC

Just saw your reply.

If x.y works, and x("y") also works, this implies to me that the latter form
is expanding to x.Properties("y") by default - which works. So if x("y")
doesn't work, this implies to me that x does not have a Properties
collection, or that collection is not used by default in the syntax x("y").

IOW, just because you can do Tabdefs("TheTableName"),
Fields("TheFieldName"), and many other similar things in Access VBA, does
not necessarily mean that you can do x("y") in all cases in all VBA
environments, IMO. IOW squared, the ability to do x("y") is a property of
the object model, not the VBA language, IMO squared.

HTH,
TC
 

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