Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import custom fields from outlook: type mismatch

Status
Not open for further replies.

georg59

Programmer
Sep 1, 2001
26
DE
Hello,
I have to write code that must import user defined fields from outlook's contacts folder. But every time i try to access from foxpro, i get a "type mismatch error". Do anyone know about this problem?

Here is the reducted code, that shows that problem:

LOCAL oOutlook,oNameSpace,oDefaultFolder
oOutlook = CREATEOBJECT("outlook.application")
oNameSpace = oOutlook.getnamespace("MAPI")
oDefaultFolder=oNameSpace.GetDefaultFolder(10)
oItems = oDefaultFolder.items
FOR EACH oItem IN oItems
? oItem.UserProperties("MyField")
ENDFOR

thanx for any help.

 
georg59

According to the Outlook object model the UserProperties represents a collection of items, not a single item.

Returns the UserProperties collection that represents all the user properties for the Outlook item.[//i]

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hello Mike Gagnon,
thanx for your quick reply. I think Your tip is right. But how is the right syntax?

I tried:

? oItem.UserProperties("MyField").Value

But foxpro gives me an ERR 1943.


Georg Nickel
Software Development
Germany
 
georg59,

I haven't tried this, so it is provided as is with no warranty :)...

? oItem.UserProperties.Item("MyField").Value

...or maybe something like...

Local nCounter
For nCounter = 1 To oItem.UserProperties.Count
?oItem.UserProperties.Item(nCounter).Name + ": " + oItem.UserProperties.Item(nCounter).Value
EndFor

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
georg59

One thing I noticed is that adding a field to the contact folder does not add the field for all contacts, but rather to the individual contact. Here is an example to pick-up the value of an added field to the contacts in Outlook.
Code:
LOCAL oOutlook,oNameSpace,oDefaultFolder
oOutlook = CREATEOBJECT("outlook.application") 
oNameSpace = oOutlook.getnamespace("MAPI")
oDefaultFolder=oNameSpace.GetDefaultFolder(10) 
loNewContact = oDefaultfolder.Items.Add()  
loNewContact.Fullname = "John Smith"
loNewContact.UserProperties.Add("Amount", 14)
loNewContact.UserProperties("Amount").Value = 100.00
loNewContact.save()
MESSAGEBOX(TRANSFORM(loNewContact.UserProperties("Amount").Value))
loNewContact.display





Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks all for your good answers. Now I'm able to solve my problem. The reason for difficulties by accessing user defined outlook fields is, that foxpro doesn't know the type of the field until you have assigned a value to it. So here is my code for importing data from outlook's contact folder. I use a yes/no field in outlook to select the contacs I want to import. The User4 field contains the information if this contact was still imported. Perhaps it helps others to solve such problems I had.

[tt]------------------
* This code imports data from outlook's contact folder
* You have a field "check" in outlook to select the contacs
*you will import. The User4 field is used to control that
*one contact isn't imported twice
*
LOCAL oOutlook,oNameSpace,oDefaultFolder
oOutlook = CREATEOBJECT("outlook.application")
oNameSpace = oOutlook.getnamespace("MAPI")
oDefaultFolder=oNameSpace.GetDefaultFolder(10)
oItems = oDefaultFolder.items
oItems.Item(1).UserProperties.Add("Check",6)
nCount=0
* For all contacs in contacs-folder
FOR i=1 TO oItems.Count
oItem=oItems.Item(i)
* Is the user defined field "Check" of type "logical"?
* We have to check this to prevent from type mismatch error
IF TYPE('oItem.UserProperties.Find("Check").Value')='L'
* Is the field set to "TRUE"?
IF oItem.UserProperties.Find("Check").Value =.T.
* Was this contact still imported?
IF oItem.User4 <> &quot;IMPORT_OK&quot;
cTitle=oItem.Title
cFirstName=oItem.FirstName
* and so on...
oItem.User4=&quot;IMPORT_OK&quot;
oItem.UserProperties.Find(&quot;Check&quot;).Value =.F.
ENDIF
ENDIF
ENDIF
oItem.Save
ENDFOR[/tt]

Georg Nickel
Software Development
Germany
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top