Changing the MessageClass

G

Gary Lemmon

So what I understand is that I can take an existing email message and change
the messageclass to a custom form save or display the item and it will now
show the custom form with the email information.

I have found several samples and it looks fairly simple. I am using the
following

Set objFolder = Session.GetDefaultFolder(olFolderCalendar)
Set oItem.MessageClass = objFolder.Items.Add("IPM.Note.Gary")
oItem.Display

The oItem is of type object and is the email that I want changed. The
display command however does not display the custom form but the old form
and email.

Any suggestions.

Gary
 
S

Sue Mosher [MVP]

Your code below attempts to create a new item with the desired class (and in an inappropriate folder), but is not correct. It should be:

Set oItem = objFolder.Items.Add("IPM.Note.Gary")

If you want to change the class of an existing item, the code would be:

oItem.MessageClass = "IPM.Note.Gary"
oItem.Save

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
G

Gary Lemmon

So my thought was that since the custom form is stored in the Personal Forms
Library that I would need to access that form via the
Session.GetDefaultFolder(olFolderCalendar)
and once I had it then I would set the current email to the retrieved custom
form.


Your code below attempts to create a new item with the desired class (and in
an inappropriate folder), but is not correct. It should be:

Set oItem = objFolder.Items.Add("IPM.Note.Gary")

If you want to change the class of an existing item, the code would be:

oItem.MessageClass = "IPM.Note.Gary"
oItem.Save

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
G

Gary Lemmon

So the code oItem.MessageClass = "IPM.Note.Gary" does not find the custom
form and the email does not change.

The form is only published in the Personal Forms Library

May be I am going at it all wrong.
I want to take any email that has come in and reply to it with a custom
form. I thought that changing the MessageClass would be the way to go.
(other problems with the reply part)

G


Your code below attempts to create a new item with the desired class (and in
an inappropriate folder), but is not correct. It should be:

Set oItem = objFolder.Items.Add("IPM.Note.Gary")

If you want to change the class of an existing item, the code would be:

oItem.MessageClass = "IPM.Note.Gary"
oItem.Save

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP]

GetDefaultFolder returns a MAPIFolder object. This has nothing to do with changing the MessageClass value, unless you're intention is to loop through all the items in that folder to change the value on all of them or to create a new item in that folder using a custom form.

Outlook has no concept of "retrieving" a custom form. Either the item is set to display a custom form or it isn't.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP]

A key issue is -- how are you instantiating oItem?

This code snippet, intended for the ThisOutlookSession VBA module, should change the class of the currently selected message, then create and display a reply.

On Error Resume Next
Set objItem = Application.ActiveExplorer.Selection(1)
If Not objItem Is Nothing Then
objItem.MessageClass = "IPM.Note.Gary"
objItem.Save
Set objReply = objItem.Reply
objReply.Display
End If


--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
G

Gary Lemmon

I still do not get a change in the base form.

When I am displaying the custom form I use the following code, and as you
pointed out it is to create a new form. I was supprised that I needed to
change the folder object by using Session.GetDefaultFolder(olFolderCalendar)
to be able to find the form (nothing else worked) . I found this in some
sample code that refered to finding a custom form in the Personal Forms
Library


Dim objFolder As Outlook.MAPIFolder
Dim myItem As Object
Dim FormName As String

On Error Resume Next

Set objFolder = Session.GetDefaultFolder(olFolderCalendar)
FormName = TrimNull(Get_Registry_Value(RegLocation, HKEY_CURRENT_USER,
"Self-Filing Name"))
FormName = "IPM.Note." + FormName
Set myItem = objFolder.Items.Add(FormName)
myItem.Display




A key issue is -- how are you instantiating oItem?

This code snippet, intended for the ThisOutlookSession VBA module, should
change the class of the currently selected message, then create and display
a reply.

On Error Resume Next
Set objItem = Application.ActiveExplorer.Selection(1)
If Not objItem Is Nothing Then
objItem.MessageClass = "IPM.Note.Gary"
objItem.Save
Set objReply = objItem.Reply
objReply.Display
End If


--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
G

Gary Lemmon

Sorry here is the code that builds the object that is passed

Dim oApp As Outlook.Application
Dim objFolder As Outlook.MAPIFolder
Dim oExp As Outlook.Explorer
Dim oSel As Outlook.Selection ' You need a selection object for
getting the selection.
Dim oItem As Object ' You don't know the type yet.
Dim i As Integer

On Error Resume Next

Set oApp = OutlookApplication
Set oExp = oApp.ActiveExplorer ' Get the ActiveExplorer.
Set oSel = oExp.Selection ' Get the selection.
Set objFolder = Session.GetDefaultFolder(olFolderCalendar)

If oSel.Count = 0 Then
MsgBox TrimNull(Get_Registry_Value(RegLocation, HKEY_CURRENT_USER,
"Error 2"))
'"You need at least one email selected for this feature to work."
Else

For i = 1 To oSel.Count ' Loop through all the currently
..selected items
Set oItem = oSel.Item(i) ' Get a selected item.
BuildForm oItem, TrimNull(Get_Registry_Value(RegLocation,
HKEY_CURRENT_USER, "Local Mail Box Name")) ' Display information
about it.
Next i

End If


A key issue is -- how are you instantiating oItem?

This code snippet, intended for the ThisOutlookSession VBA module, should
change the class of the currently selected message, then create and display
a reply.

On Error Resume Next
Set objItem = Application.ActiveExplorer.Selection(1)
If Not objItem Is Nothing Then
objItem.MessageClass = "IPM.Note.Gary"
objItem.Save
Set objReply = objItem.Reply
objReply.Display
End If


--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP]

What does the BuildForm procedure do? Did you try the code I suggested?
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
G

Gary Lemmon

The BuildForm procedure accepts the oItem as an object and then I ran the
code that you gave me.

The object was saved and received a different Icon (from where I do not
know) and was listed in the folder as "this contains active content that can
not be displayed in the preview pane." When I open it up all is fine.

It does not how ever display the custom form.

So I am assuming that outlook is having problems since the custom form is
not associated with the folder.
What do you think.

G


What does the BuildForm procedure do? Did you try the code I suggested?
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP]

Actually, that sounds like it worked just fine. The icon is the one from your custom form's Properties page. The "active content" message also indicates that the item is a custom form with code behind it.

The problem might be that you never designed a read layout for the custom form, so Outlook is displaying the default.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
G

Gary Lemmon

You are correct the Icon was from the custom form. So why does it not show
when I view it? Any thoughts?

Is there another way to do this that might result in more success?

If you have no other thoughts, I want to thank you for your assistance. I
have seen referances to your books and have looked through all sorts of code
in the last week. Is there some location where the Outlook object model is
better explained? I am use to being able to dig into API code and or have
very technical resources that expose relationships and the like. For
instance I was looking for a way to access the body of an email and all the
samples were using "subject" or "from" in the header. I never found
documentation that show all of the constants with an explination of their
functionality. Any way thanks for your help.

G

Actually, that sounds like it worked just fine. The icon is the one from
your custom form's Properties page. The "active content" message also
indicates that the item is a custom form with code behind it.

The problem might be that you never designed a read layout for the custom
form, so Outlook is displaying the default.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP]

Repeating: Did you actually design a read layout for the form or just a compose layout? If you don't understand what that means, open the form in design mode again. You should see two buttons on the toolbar -- Edit Compose Page and Edit Read Page. Click the latter to see what layout is in effect when you open a received or sent item.

For information on the Outlook object model, check the object browser: Press Alt+F11 to open the VBA environment in Outlook, then press F2. Select any object, property, or method, then press F1 for the corresponding Help topic.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
G

Gary Lemmon

Thanks for the lesson on custom forms. I am sure that there are still
things that I need to dot to get it to work but I am going to wait until I
can do some testing on the network where there are some "real" custom forms
(designed by others).

Thanks again.

G

Repeating: Did you actually design a read layout for the form or just a
compose layout? If you don't understand what that means, open the form in
design mode again. You should see two buttons on the toolbar -- Edit Compose
Page and Edit Read Page. Click the latter to see what layout is in effect
when you open a received or sent item.

For information on the Outlook object model, check the object browser: Press
Alt+F11 to open the VBA environment in Outlook, then press F2. Select any
object, property, or method, then press F1 for the corresponding Help topic.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
G

Gary Lemmon

Taking a recieved email and doing a reply with a different form type(a
custom form that has custom functionality)

Like I indicated in my last message I was going to wait until I could get to
the client where this was already in place. The projec is to replace an
existing Add-in for which the company does not have any of the code. So I
know that the previous developer found a way to accomplish this. My code
did not work.

Here are my observations. I believe that the messageclass does change but
because the mail item is in being retrieve from a folder that is associated
with the default messageclass that is what is displayed. I have no problem
displaying the custom form as a new form. I believe it has changed
(messageclass) because when I close the email (because it is the wrong form)
it ask me if I want to save it (indicating to me that the message class has
changed back to the defalult).

So I thought well maybe the other Add-in was just opening up a new mail
item (custom form) and filling in the info from the other email. Would work
fine but I run into security problems filling in the to and from lines.

Any thoughts.

Thanks

G


Repeating: Did you actually design a read layout for the form or just a
compose layout? If you don't understand what that means, open the form in
design mode again. You should see two buttons on the toolbar -- Edit Compose
Page and Edit Read Page. Click the latter to see what layout is in effect
when you open a received or sent item.

For information on the Outlook object model, check the object browser: Press
Alt+F11 to open the VBA environment in Outlook, then press F2. Select any
object, property, or method, then press F1 for the corresponding Help topic.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 

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