How to access a control in an outlook form?

M

MeAgin

Hi all,

I want to assign some values to a control in a form in its activate event.
How can I get a handle to the control in a VB.NET add-in?


I tried the following with no luck,


Dim objItem As Outlook.MailItem
objItem = VBAInspector.CurrentItem

Dim opage As Outlook.PropertyPage
opage = objItem.GetInspector.ModifiedFormPages("P.2")

Dim oControl As TextBox
oControl = opage.controls("TextBox1")
oControl.Text = "Test message"

Thanks in advance.
Nadee.
 
M

MeAgin

I think I have found the problem. It seems when the line,
opage = objItem.GetInspector.ModifiedFormPages("P.2")
is executed rest of the code following it is not executed. May be because
the code is in the Activate method. Is there a way to overcome this?

Any advice would be greatly appreciated.
Nadeera
 
K

Ken Slovak - [MVP - Outlook]

Put in some error handling and try...catch blocks to see what exception is
being thrown and where. Step your code to find out what's going on. See if
you're getting a valid opage object.

You can use the VBAInspector object to get ModifiedFormPages, BTW. You don't
need to go backwards from objItem.

You are handling this in the Inspector.Activate event? Before that the form
page probably would not be valid.
 
M

MeAgin

Hi Ken,

Thanks for your thoughts.
There's no exception occur here. Following is what I noticed when I
debugged.

As soon as the line,
opage = objItem.GetInspector.ModifiedFormPages("P.2")

is executed the mail form is bring to front and the execution is halted. If
I click somewhere else and click on the mail form again the Activate event
will be fired again but as soon as the above line is found again the
execution is halted again. It seems when the above method is called the form
is activated again. But this is also not recursive so I can set a flag and
return to the called method. In the call stack only one method is shown.

How to overcome this? My requirement is populate some controls when loading
the mail item by double clicking.

Thanks.

Nadee
 
K

Ken Slovak - [MVP - Outlook]

If you only want the initialization code to run once just set a Boolean flag
that tells you it's the first Activate event. After that first one the flag
will be set and your Activate code can just exit gracefully.
 
M

MeAgin

Hi,



I have already checked this with no luck. When I return after checking the
flag it doesn't return to the place from where it was called from. Instead
it goes to end of the method. I have a feeling that this is not a recursive
method call but happens because of something else.

Anyway without going this way is there any other way to access controls in
the mail form from my add-in?


Thaks.

Nadee
 
K

Ken Slovak - [MVP - Outlook]

Activate is the best event to use, if you use Item_Open some things may not
be fully instantiated at that time. If it goes to the end of the method it's
likely that some error is causing the intermediate code to be skipped. I'd
comment out the error handler and step the code to see where any errors are
happening and what the error is.
 

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