Cant access User-Defined field via vbscript until the Custom Form has been "posted"

R

Robert Brown

HI.

I have a custom form within a Public Folder for Mail/Post items. On
this form I have created a NEW field called DAYS and set a value of 0
as the default.

Within the folder View, I have added the Days Column.

When a new email arrives to this public folder, I apply the new custom
form without a problem, but the column for DAYS is blank. If I open
the item, the field DAYS has the default value in it. If I close the
item (without saving it) the column is still blank in the folder view.
If I actually save it, then the column will display the default value
of 0.

Ok, what I am trying to achieve is that when the new item arrives the
default value is "posted" whatever with the form. I then have a
VBScript that runs at 4pm each day, and increments the DAYS value.
Once it gets to a certain day count, I automatically email an
auto-response.

The problem is that if the mail item has not been saved prior to
this(by opening it and then saving it manually), then I get a MAPI-E
error stating the object doesnt exist when I try to retreive the value
through a vbscript. I can't even programmatically insert a value until
the manual save is done. Once I have done the manual save, the
vbscript works perfectly with no errors.

I presumed that when a mail item arrived it was being "saved" like
when a manual post has occured. So, what can I do to fix this. Should
I put some code in the custom form to fire when the item is created?
Has anyone got any ideas?

Below is the code i use to read the field. Presume that I have opened
a mapi session and have navigated to the folder/subfolder in question.

Thanks,
Robert

set objMessages = objSubFolder.Messages

for each objMessage in objMessages
set objFields = objMessage.fields
set objField = objFields.item("Days")
zz = cint(objField)
objFields.item("Days").value = CStr(zz+1)
objmessage.update
next
 
R

Robert Brown

Thanks for the Reply Sue..

I was hoping this would be the case. However, I have put in the code
to add the field but now I get in the error log: Error 424 Object
Required

Here is a snippet of the code.

With objRecord.Fields

' Change MAPI message class
..Item("http://schemas.microsoft.com/exchange/outlookmessageclass").Value
= MESSAGE_CLASS

Set objKeysField = .Add("Days", vbString)
objKeysField.Value = "-1"

' Save changes
..Update

End With


I have declared objKeysField and declared vbString = 8

Can you see where the error might be when I try to add the field.

Thanks again,
Robert
 
S

Sue Mosher [MVP-Outlook]

This is CDO 1.21 code? As the page at http://www.cdolive.com/cdo10.htm
explains, you use this syntax to add an Outlook custom field:


' Create/write a Microsoft Outlook item custom field
objMessage.Fields.Add "<PropertyTag>", <PropertyType>, _
"<YourFieldValue>", CdoPropSetID5
' For Example:
objMessage.Fields.Add "PersonRole", vbString, "HR Lead", _
"2903020000000000C000000000000046"

vbString is a VBScript constant and doesn't need to be declared.

BTW, you can use the Message.Type property to change the message class.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Robert Brown said:
Thanks for the Reply Sue..

I was hoping this would be the case. However, I have put in the code
to add the field but now I get in the error log: Error 424 Object
Required

Here is a snippet of the code.

With objRecord.Fields

' Change MAPI message class
.Item("http://schemas.microsoft.com/exchange/outlookmessageclass").Value
= MESSAGE_CLASS

Set objKeysField = .Add("Days", vbString)
objKeysField.Value = "-1"

' Save changes
.Update

End With


I have declared objKeysField and declared vbString = 8

Can you see where the error might be when I try to add the field.

Thanks again,
Robert




Sue Mosher [MVP-Outlook] <[email protected]> wrote in message
In the script that changes the message clasee, use Fields.Add to add the property. After that, you'll be able to set the value.
 
R

Robert Brown

Hi Sue..

Thanks for the reply. I had a look at this area before but didn't
think it was the right way.

Well.. it is and now I am very happy. I was able to add the Custom
Field with the exact sample given (but changed the names) and then I
was able to add the default value.

Thanks again,
Robert

Sue Mosher said:
This is CDO 1.21 code? As the page at http://www.cdolive.com/cdo10.htm
explains, you use this syntax to add an Outlook custom field:


' Create/write a Microsoft Outlook item custom field
objMessage.Fields.Add "<PropertyTag>", <PropertyType>, _
"<YourFieldValue>", CdoPropSetID5
' For Example:
objMessage.Fields.Add "PersonRole", vbString, "HR Lead", _
"2903020000000000C000000000000046"

vbString is a VBScript constant and doesn't need to be declared.

BTW, you can use the Message.Type property to change the message class.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Robert Brown said:
Thanks for the Reply Sue..

I was hoping this would be the case. However, I have put in the code
to add the field but now I get in the error log: Error 424 Object
Required

Here is a snippet of the code.

With objRecord.Fields

' Change MAPI message class
.Item("http://schemas.microsoft.com/exchange/outlookmessageclass").Value
= MESSAGE_CLASS

Set objKeysField = .Add("Days", vbString)
objKeysField.Value = "-1"

' Save changes
.Update

End With


I have declared objKeysField and declared vbString = 8

Can you see where the error might be when I try to add the field.

Thanks again,
Robert




Sue Mosher [MVP-Outlook] <[email protected]> wrote in message
In the script that changes the message clasee, use Fields.Add to add the property. After that, you'll be able to set the value.

:

HI.

I have a custom form within a Public Folder for Mail/Post items. On
this form I have created a NEW field called DAYS and set a value of 0
as the default.

Within the folder View, I have added the Days Column.

When a new email arrives to this public folder, I apply the new custom
form without a problem, but the column for DAYS is blank. If I open
the item, the field DAYS has the default value in it. If I close the
item (without saving it) the column is still blank in the folder view.
If I actually save it, then the column will display the default value
of 0.

Ok, what I am trying to achieve is that when the new item arrives the
default value is "posted" whatever with the form. I then have a
VBScript that runs at 4pm each day, and increments the DAYS value.
Once it gets to a certain day count, I automatically email an
auto-response.

The problem is that if the mail item has not been saved prior to
this(by opening it and then saving it manually), then I get a MAPI-E
error stating the object doesnt exist when I try to retreive the value
through a vbscript. I can't even programmatically insert a value until
the manual save is done. Once I have done the manual save, the
vbscript works perfectly with no errors.

I presumed that when a mail item arrived it was being "saved" like
when a manual post has occured. So, what can I do to fix this. Should
I put some code in the custom form to fire when the item is created?
Has anyone got any ideas?

Below is the code i use to read the field. Presume that I have opened
a mapi session and have navigated to the folder/subfolder in question.

Thanks,
Robert

set objMessages = objSubFolder.Messages

for each objMessage in objMessages
set objFields = objMessage.fields
set objField = objFields.item("Days")
zz = cint(objField)
objFields.item("Days").value = CStr(zz+1)
objmessage.update
next
 

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