Saving to a custom form

L

Lori

have a custom page in Outlook 2003 that is created for contact
items. Developed with VS.NET 1.1.


I have a problem saving values to my controls. The first time the page
is created, I am able to load a picture to my image control based on
the value of my text box. Everything works just fine.


The problems occurs when I update the information. When I'm re-open the

contact, I am able to change the image source and text. I can click on
general tab, details tab, back to test tab and everythings is okay.
However, when I close the contact item and open it up again, I get the
original information which I had saved and not the updated informaton.


I've include some of my code. Is it necessary to use User-defined
fields? Information is saved the firsttime around but can't be updated.



Code that creates the custom form
Private Sub CreateTestTab()


Try


myPages = m_olContactItem.GetInspector.ModifiedFormPages
myPage = myPages.Add("Test")


ctrls = myPage.Controls
'Create TextBox Control
If (ctrls.Count < 0) Then
txtMapSource = ctrls.Add("Forms.TextBox.1", "txtMapSource",
True)
imgTest = ctrls.Add("Forms.Image.1", "imgTest", True)
btnGetMap = ctrls.Add("Forms.CommandButton.1", "btnGetMap")
End If


txtMapSource.Visible = True
txtMapSource.Height = 24
txtMapSource.Width = 350
txtMapSource.Left = 120
txtMapSource.Top = 32


imgTest.Height = 300
imgTest.Width = 300
imgTest.Left = 16
imgTest.Top = 88
imgTest.Visible = True


btnGetMap.Caption = "Get Test map"
btnGetMap.Visible = True
btnGetMap.Height = 24
btnGetMap.Width = 96
btnGetMap.Left = 16
btnGetMap.Top = 32


Catch ex As Exception
MsgBox("Error: " + ex.Message)


Finally
DisposeObject(myPages)
DisposeObject(myPage)
DisposeObject(myPagesCheck)
DisposeObject(ctrls)
DisposeObject(oWeb)
DisposeObject(txtMapSource)


End Try


End Sub


Code to update control values:


Private Sub btnGetMap_Click() Handles btnGetMap.Click
Dim imageNet As System.Drawing.Image
Dim ctrls As MSForms.Controls 'Controls collection
Dim txtMapSource As MSForms.Control
Dim httpStream As Stream
Dim httpWReq As HttpWebRequest
Dim httpWResp As HttpWebResponse


Try


txtMapSource =
m_olContactItem.GetInspector.ModifiedFormPages("Test").Controls("txtMapSour­ce")

imgTest =
m_olContactItem.GetInspector.ModifiedFormPages("Test").Controls("imgTest")



If (txtMapSource.Text <> "") Then
httpWReq = CType(WebRequest.Create(txtMapSource.Text),
HttpWebRequest)
httpWResp = CType(httpWReq.GetResponse(), HttpWebResponse)
imageNet =
System.Drawing.Image.FromStream(httpWResp.GetResponseStream())
imgTest.Picture = Compatibility.VB6.ImageToIPicture(imageNet)
End If


m_olContactItem.Save()


Catch ex As Exception
MsgBox("Error button popup : " + ex.Message)
Finally


End Try


End Sub


Thanks in advance for your help.
 
S

Sue Mosher [MVP-Outlook]

Yes, if you want data to be persisted, you need to be saving it in Outlook properties, built-in or custom. The form design is a UI template, not a data record. (And have you looked to see how much your inflating the size of each item by using a one-off form?)

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



have a custom page in Outlook 2003 that is created for contact
items. Developed with VS.NET 1.1.


I have a problem saving values to my controls. The first time the page
is created, I am able to load a picture to my image control based on
the value of my text box. Everything works just fine.


The problems occurs when I update the information. When I'm re-open the

contact, I am able to change the image source and text. I can click on
general tab, details tab, back to test tab and everythings is okay.
However, when I close the contact item and open it up again, I get the
original information which I had saved and not the updated informaton.


I've include some of my code. Is it necessary to use User-defined
fields? Information is saved the firsttime around but can't be updated.



Code that creates the custom form
Private Sub CreateTestTab()


Try


myPages = m_olContactItem.GetInspector.ModifiedFormPages
myPage = myPages.Add("Test")


ctrls = myPage.Controls
'Create TextBox Control
If (ctrls.Count < 0) Then
txtMapSource = ctrls.Add("Forms.TextBox.1", "txtMapSource",
True)
imgTest = ctrls.Add("Forms.Image.1", "imgTest", True)
btnGetMap = ctrls.Add("Forms.CommandButton.1", "btnGetMap")
End If


txtMapSource.Visible = True
txtMapSource.Height = 24
txtMapSource.Width = 350
txtMapSource.Left = 120
txtMapSource.Top = 32


imgTest.Height = 300
imgTest.Width = 300
imgTest.Left = 16
imgTest.Top = 88
imgTest.Visible = True


btnGetMap.Caption = "Get Test map"
btnGetMap.Visible = True
btnGetMap.Height = 24
btnGetMap.Width = 96
btnGetMap.Left = 16
btnGetMap.Top = 32


Catch ex As Exception
MsgBox("Error: " + ex.Message)


Finally
DisposeObject(myPages)
DisposeObject(myPage)
DisposeObject(myPagesCheck)
DisposeObject(ctrls)
DisposeObject(oWeb)
DisposeObject(txtMapSource)


End Try


End Sub


Code to update control values:


Private Sub btnGetMap_Click() Handles btnGetMap.Click
Dim imageNet As System.Drawing.Image
Dim ctrls As MSForms.Controls 'Controls collection
Dim txtMapSource As MSForms.Control
Dim httpStream As Stream
Dim httpWReq As HttpWebRequest
Dim httpWResp As HttpWebResponse


Try


txtMapSource =
m_olContactItem.GetInspector.ModifiedFormPages("Test").Controls("txtMapSour­ce")

imgTest =
m_olContactItem.GetInspector.ModifiedFormPages("Test").Controls("imgTest")



If (txtMapSource.Text <> "") Then
httpWReq = CType(WebRequest.Create(txtMapSource.Text),
HttpWebRequest)
httpWResp = CType(httpWReq.GetResponse(), HttpWebResponse)
imageNet =
System.Drawing.Image.FromStream(httpWResp.GetResponseStream())
imgTest.Picture = Compatibility.VB6.ImageToIPicture(imageNet)
End If


m_olContactItem.Save()


Catch ex As Exception
MsgBox("Error button popup : " + ex.Message)
Finally


End Try


End Sub


Thanks in advance for your help.
 
L

Lori

Hi! Thanks for your speedy reply. I am now using user-defined
properties and everything works great. However, your reply has opened
up several questions which I am hoping you may have answers to.

1. Where do I look to see the size of the items. How can avoid this.
What are the consequences?
2. How can I avoid one-off forms and still achieve my goals. (having a
tab with controls that populate an image)
3. Besides MSDN website, can you suggest a book or site where I can get
answer to these questions +more info.

Thanks again in advance for your help.

/Lori
 
S

Sue Mosher [MVP-Outlook]

1) Add the Size field to any view or use Outlook Spy or MFCMAPI.

2) Design the form with the controls you need rather than adding them at run time. To use an image control programmatically, see http://www.outlookcode.com/d/formpicture.htm#control .

3) See my signature.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
L

Lori

Thanks Sue. I'll be buying your book.

Regarding one-off forms, I don't think that I'll be able to avoid this.
Reason being that, the program that I am writing will be used by
others, so I need to create the form and controls for them when they
install the add-in.

Thanks again.

/Lori
 
S

Sue Mosher [MVP-Outlook]

You can include code in your add-in to publish the form using the FormDescription.PublishForm method. This is what add-ins like Microsoft's own Business Contact Manager do.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
L

Lori

Hi again!

I have tried the FormDescription.PublishForm, my code looks like this:
m_olContactItem.FormDescription.Name = "Test"
m_olContactItem.FormDescription.PublishForm(Outlook.OlFormRegistry.olPersonalRegistry).

This creates a form called Test. I'm not sure if this is what I want to
do. What I want to do is save my tab with its controls to the original
Contact Form. Is this possible?

Thanks in advance.

/Lori
 
S

Sue Mosher [MVP-Outlook]

No, that's not how custom forms work. You can't modify the original built-in form. What you can do is create your own new custom form based on the built-in form. In some scenarios, you may want to make that new published form either the global default form or the default for a particular folder. See http://www.outlookcode.com/d/newdefaultform.htm

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
L

Lori

Ok. Now I understand. Thanks again. I guess I should read the entire
book instead of jumping. Got some reading to do for the weekend.

Thanks again, and have a great weekend.

/Lori
No, that's not how custom forms work. You can't modify the original built-in form. What you can do is create your own new custom form based on the built-in form. In some scenarios, you may want to make that new published form either the global default form or the default for a particular folder. See http://www.outlookcode.com/d/newdefaultform.htm

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Lori said:
Hi again!

I have tried the FormDescription.PublishForm, my code looks like this:
m_olContactItem.FormDescription.Name = "Test"
m_olContactItem.FormDescription.PublishForm(Outlook.OlFormRegistry.olPersonalRegistry).

This creates a form called Test. I'm not sure if this is what I want to
do. What I want to do is save my tab with its controls to the original
Contact Form. Is this possible?
Sue Mosher [MVP-Outlook] wrote:
You can include code in your add-in to publish the form using the FormDescription.PublishForm method. This is what add-ins like Microsoft's own Business Contact Manager do.

Thanks Sue. I'll be buying your book.

Regarding one-off forms, I don't think that I'll be able to avoid this.
Reason being that, the program that I am writing will be used by
others, so I need to create the form and controls for them when they
install the add-in.
 

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