Item.Add()

K

k.mitz

I have been using the following code as part of a web application.

Set ol = CreateObject("Outlook.Application")
Set ns = ol.GetNamespace("MAPI")
Set fdr = ns.Folders("Public Folders").Folders("All Public
Folders").Folders("sg.com").Folders("JOB SCHEDULE")
Set itm = fdr.Items.Add()
Set psn = itm.UserProperties.Add("SGPersonnel",1, True)
psn.Value = "Jeff"
Set act = itm.UserProperties.Add("ActID",3, True)
act.Value = "123456789"
Set cust = itm.UserProperties.Add("CustID",3, True)
cust.Value = "AKL158478"
itm.Location = "New York, NY"
...

I would now like to be able to display each item matching the ActID
(which is a userproperty). I understand that to use the Restrict
method the field must exist in the folder.

Note: I created & published a form with the above mentioned fields and
checked "When posting to this folder use <<myForm>>" on the folder
properties page.

Set ol = CreateObject("Outlook.Application")
Set ns = ol.GetNamespace("MAPI")
Set fdr = ns.Folders("Public Folders").Folders("All Public
Folders").Folders("sg.com").Folders("JOB SCHEDULE")
Set res = fdr.Restrict("[ActID] = '123456789'")
MsgBox VarType(res) 'returns 9 - object
MsgBox res.Count ' returns 0
...

The Restrict method completes successfully, but never finds any
results. I can display the item using the Find method, but it takes a
long, long time.

My question is, does the above code create the fields in the folder, or
do I need to use "IPM.Appointment.SG" when I create the item using the
Add method?

Can I programatically change all the existing items so that they use
the proper form/folder combo so I can use the Restrict method?

Thanks.
 
K

Ken Slovak

Use code to iterate the items in the folder and change their MessageClass
property to your custom message class.

I've found that I need to create at least one item with the UserProperty I
want added that item before the property shows up as a field in the folder.
YMMV

Programming questions like this are best posted in the
microsoft.public.outlook.program_vba group.
 
M

Milly Staples [MVP - Outlook]

This type of question can best be answered by those who are more experienced
with programming in Outlook.

You may want to post this in the microsoft.public.outlook.program_forms
group or in the microsoft.public.outlook.program_vba group.

You will probably receive a faster and more expert answer over there.


--
Milly Staples [MVP - Outlook]

Post all replies to the group to keep the discussion intact. Due to
the (insert latest virus name here) virus, all mail sent to my personal
account will be deleted without reading.

After furious head scratching, (e-mail address removed) asked:

| I have been using the following code as part of a web application.
|
| Set ol = CreateObject("Outlook.Application")
| Set ns = ol.GetNamespace("MAPI")
| Set fdr = ns.Folders("Public Folders").Folders("All Public
| Folders").Folders("sg.com").Folders("JOB SCHEDULE")
| Set itm = fdr.Items.Add()
| Set psn = itm.UserProperties.Add("SGPersonnel",1, True)
| psn.Value = "Jeff"
| Set act = itm.UserProperties.Add("ActID",3, True)
| act.Value = "123456789"
| Set cust = itm.UserProperties.Add("CustID",3, True)
| cust.Value = "AKL158478"
| itm.Location = "New York, NY"
| ...
|
| I would now like to be able to display each item matching the ActID
| (which is a userproperty). I understand that to use the Restrict
| method the field must exist in the folder.
|
| Note: I created & published a form with the above mentioned fields and
| checked "When posting to this folder use <<myForm>>" on the folder
| properties page.
|
| Set ol = CreateObject("Outlook.Application")
| Set ns = ol.GetNamespace("MAPI")
| Set fdr = ns.Folders("Public Folders").Folders("All Public
| Folders").Folders("sg.com").Folders("JOB SCHEDULE")
| Set res = fdr.Restrict("[ActID] = '123456789'")
| MsgBox VarType(res) 'returns 9 - object
| MsgBox res.Count ' returns 0
| ...
|
| The Restrict method completes successfully, but never finds any
| results. I can display the item using the Find method, but it takes a
| long, long time.
|
| My question is, does the above code create the fields in the folder,
| or do I need to use "IPM.Appointment.SG" when I create the item using
| the Add method?
|
| Can I programatically change all the existing items so that they use
| the proper form/folder combo so I can use the Restrict method?
|
| Thanks.
 
K

k.mitz

I discovered that a few hundred of the AppointmentItems were not of the
MessageClass I originally set up the folder with. The Items that were
programatically generated have MessageClass = 'IPM.Appointment.SG'.
The clients somehow used the generic version for some appointments. I
just used Restrict twice, once for MessageClass, and once more for
ActID.

Thanks!
 

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