Outlook Custom Forms and .Net

D

Duncan McCreadie

I am programming a .net based addin for Outlook and want to access the
values
of certain controls on an Outlook Custom Form. These controls are from
FM20.dll, the two in particular causing me grief are the checkBox and
comboBox controls. In vbscript I can access the controls and set their
values happily, but in .net the checkbox.value is returned as an Object
(other properties are returned as their more usual types like boolean,
string etc). In the case of the combobox I am trying to use the .List()
call to assign an array to it, but in .net it seems to expect an Object.
Attempts to CType the variable to an Object result in failure.

Does anyone have any experience of accessing and using controls on Outlook
forms from .net?

Thanks in anticipation,

Duncan
 
S

Sue Mosher [MVP-Outlook]

I haven't tried it, but if you have some sample code, I'll give it a whack
here.
 
D

Duncan McCreadie

Thanks for the offer - here goes:

Create a form (mine is a contactitem) with a combobox and checkbox on. The
code to use them is then something like:
Sub item_Open()

'

' User opened connect.applicationobject.activeinspector.currentitem

'

Dim objPage As Object

Dim itm As Microsoft.Office.Interop.Outlook.ContactItem

Dim ComboBox1 As MSForms.ComboBox ' Company



Dim myInspector As Microsoft.Office.Interop.Outlook.Inspector

Dim strRestrict As String

Dim restricted As Microsoft.Office.Interop.Outlook.Items

Dim i As Integer

On Error Resume Next

objPage =
Connect.applicationObject.ActiveInspector.ModifiedFormPages("General")

' Load list of existing companies

ComboBox1 = objPage.controls("ORGComboBox1")

'ComboBox1.List() = Connect.ReturnCos this is the original code -
connect.returncos returns an array

'The following is an alternative that also fails

For i = 0 To UBound(Connect.g_arrCompanies)

ComboBox1.AddItem(CType(Connect.g_arrCompanies(i), Object))

Next

etc
Dim dummy As Object


Dim chkBox1 As MSForms.CheckBox

chkBox1 = objPage.Controls("CheckBox1")
dummy = chkBox1.Value
If dummy = "true" Then

filter &= " AND [CurrentJob] = 'Yes' "

End If

' nb tried it without the intermediate use of dummy as well to no avail


It all works if used on the form itself in VBscript i.e. connect.returncos
does return the array g_arrCompanies from the .net code.

Thanks in anticipation.

Duncan
 
S

Sue Mosher [MVP-Outlook]

Thanks. I can't even get past the ModifiedFormPages statement in VB.Net.
I'll ask around and report back.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Duncan McCreadie said:
Thanks for the offer - here goes:

Create a form (mine is a contactitem) with a combobox and checkbox on. The
code to use them is then something like:
Sub item_Open()

'

' User opened connect.applicationobject.activeinspector.currentitem

'

Dim objPage As Object

Dim itm As Microsoft.Office.Interop.Outlook.ContactItem

Dim ComboBox1 As MSForms.ComboBox ' Company



Dim myInspector As Microsoft.Office.Interop.Outlook.Inspector

Dim strRestrict As String

Dim restricted As Microsoft.Office.Interop.Outlook.Items

Dim i As Integer

On Error Resume Next

objPage =
Connect.applicationObject.ActiveInspector.ModifiedFormPages("General")

' Load list of existing companies

ComboBox1 = objPage.controls("ORGComboBox1")

'ComboBox1.List() = Connect.ReturnCos this is the original code -
connect.returncos returns an array

'The following is an alternative that also fails

For i = 0 To UBound(Connect.g_arrCompanies)

ComboBox1.AddItem(CType(Connect.g_arrCompanies(i), Object))

Next

etc
Dim dummy As Object


Dim chkBox1 As MSForms.CheckBox

chkBox1 = objPage.Controls("CheckBox1")
dummy = chkBox1.Value
If dummy = "true" Then

filter &= " AND [CurrentJob] = 'Yes' "

End If

' nb tried it without the intermediate use of dummy as well to no avail


It all works if used on the form itself in VBscript i.e. connect.returncos
does return the array g_arrCompanies from the .net code.

Thanks in anticipation.

Duncan

Sue Mosher said:
I haven't tried it, but if you have some sample code, I'll give it a whack
here.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
D

Duncan McCreadie

The only reason I think I get past the modifiedformpage issue is that I also
use OutlookViewControls and they are working properly (as they use a
different (more complete) library to the Forms controls).

Thanks for the help,

Duncan
Sue Mosher said:
Thanks. I can't even get past the ModifiedFormPages statement in VB.Net.
I'll ask around and report back.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Duncan McCreadie said:
Thanks for the offer - here goes:

Create a form (mine is a contactitem) with a combobox and checkbox on. The
code to use them is then something like:
Sub item_Open()

'

' User opened connect.applicationobject.activeinspector.currentitem

'

Dim objPage As Object

Dim itm As Microsoft.Office.Interop.Outlook.ContactItem

Dim ComboBox1 As MSForms.ComboBox ' Company



Dim myInspector As Microsoft.Office.Interop.Outlook.Inspector

Dim strRestrict As String

Dim restricted As Microsoft.Office.Interop.Outlook.Items

Dim i As Integer

On Error Resume Next

objPage =
Connect.applicationObject.ActiveInspector.ModifiedFormPages("General")

' Load list of existing companies

ComboBox1 = objPage.controls("ORGComboBox1")

'ComboBox1.List() = Connect.ReturnCos this is the original code -
connect.returncos returns an array

'The following is an alternative that also fails

For i = 0 To UBound(Connect.g_arrCompanies)

ComboBox1.AddItem(CType(Connect.g_arrCompanies(i), Object))

Next

etc
Dim dummy As Object


Dim chkBox1 As MSForms.CheckBox

chkBox1 = objPage.Controls("CheckBox1")
dummy = chkBox1.Value
If dummy = "true" Then

filter &= " AND [CurrentJob] = 'Yes' "

End If

' nb tried it without the intermediate use of dummy as well to no avail


It all works if used on the form itself in VBscript i.e. connect.returncos
does return the array g_arrCompanies from the .net code.

Thanks in anticipation.

Duncan

Sue Mosher said:
I haven't tried it, but if you have some sample code, I'll give it a whack
here.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I am programming a .net based addin for Outlook and want to access the
values
of certain controls on an Outlook Custom Form. These controls are from
FM20.dll, the two in particular causing me grief are the checkBox and
comboBox controls. In vbscript I can access the controls and set their
values happily, but in .net the checkbox.value is returned as an Object
(other properties are returned as their more usual types like boolean,
string etc). In the case of the combobox I am trying to use the .List()
call to assign an array to it, but in .net it seems to expect an Object.
Attempts to CType the variable to an Object result in failure.

Does anyone have any experience of accessing and using controls on Outlook
forms from .net?

Thanks in anticipation,

Duncan
 
D

Duncan McCreadie

After days of searching, I found this in the Microsoft Support which might
help http://support.microsoft.com/default.aspx?scid=kb;en-us;824009 ! It
turns out I had the wrong one and that's why half the properties were
hidden! Sorry for wasting your time......

Duncan

(Now to get the rest of my code off the custom forms and into .net )


Sue Mosher said:
Thanks. I can't even get past the ModifiedFormPages statement in VB.Net.
I'll ask around and report back.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Duncan McCreadie said:
Thanks for the offer - here goes:

Create a form (mine is a contactitem) with a combobox and checkbox on. The
code to use them is then something like:
Sub item_Open()

'

' User opened connect.applicationobject.activeinspector.currentitem

'

Dim objPage As Object

Dim itm As Microsoft.Office.Interop.Outlook.ContactItem

Dim ComboBox1 As MSForms.ComboBox ' Company



Dim myInspector As Microsoft.Office.Interop.Outlook.Inspector

Dim strRestrict As String

Dim restricted As Microsoft.Office.Interop.Outlook.Items

Dim i As Integer

On Error Resume Next

objPage =
Connect.applicationObject.ActiveInspector.ModifiedFormPages("General")

' Load list of existing companies

ComboBox1 = objPage.controls("ORGComboBox1")

'ComboBox1.List() = Connect.ReturnCos this is the original code -
connect.returncos returns an array

'The following is an alternative that also fails

For i = 0 To UBound(Connect.g_arrCompanies)

ComboBox1.AddItem(CType(Connect.g_arrCompanies(i), Object))

Next

etc
Dim dummy As Object


Dim chkBox1 As MSForms.CheckBox

chkBox1 = objPage.Controls("CheckBox1")
dummy = chkBox1.Value
If dummy = "true" Then

filter &= " AND [CurrentJob] = 'Yes' "

End If

' nb tried it without the intermediate use of dummy as well to no avail


It all works if used on the form itself in VBscript i.e. connect.returncos
does return the array g_arrCompanies from the .net code.

Thanks in anticipation.

Duncan

Sue Mosher said:
I haven't tried it, but if you have some sample code, I'll give it a whack
here.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I am programming a .net based addin for Outlook and want to access the
values
of certain controls on an Outlook Custom Form. These controls are from
FM20.dll, the two in particular causing me grief are the checkBox and
comboBox controls. In vbscript I can access the controls and set their
values happily, but in .net the checkbox.value is returned as an Object
(other properties are returned as their more usual types like boolean,
string etc). In the case of the combobox I am trying to use the .List()
call to assign an array to it, but in .net it seems to expect an Object.
Attempts to CType the variable to an Object result in failure.

Does anyone have any experience of accessing and using controls on Outlook
forms from .net?

Thanks in anticipation,

Duncan
 
S

Sue Mosher [MVP-Outlook]

Doh! Not a waste of time at all! And I even remember having read that
article. Thanks for reminding me about it.

Unfortunately, I still can't get my code to run past the ModifiedFormPages
statement, though. VB.Net shows it as a System.__COMObject type with no
properties even after following all the instructions in the article,
including removing the locally created PIA.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Duncan McCreadie said:
After days of searching, I found this in the Microsoft Support which might
help http://support.microsoft.com/default.aspx?scid=kb;en-us;824009 ! It
turns out I had the wrong one and that's why half the properties were
hidden! Sorry for wasting your time......
Duncan McCreadie said:
Thanks for the offer - here goes:

Create a form (mine is a contactitem) with a combobox and checkbox on. The
code to use them is then something like:
Sub item_Open()

'

' User opened connect.applicationobject.activeinspector.currentitem

'

Dim objPage As Object

Dim itm As Microsoft.Office.Interop.Outlook.ContactItem

Dim ComboBox1 As MSForms.ComboBox ' Company



Dim myInspector As Microsoft.Office.Interop.Outlook.Inspector

Dim strRestrict As String

Dim restricted As Microsoft.Office.Interop.Outlook.Items

Dim i As Integer

On Error Resume Next

objPage =
Connect.applicationObject.ActiveInspector.ModifiedFormPages("General")

' Load list of existing companies

ComboBox1 = objPage.controls("ORGComboBox1")

'ComboBox1.List() = Connect.ReturnCos this is the original code -
connect.returncos returns an array

'The following is an alternative that also fails

For i = 0 To UBound(Connect.g_arrCompanies)

ComboBox1.AddItem(CType(Connect.g_arrCompanies(i), Object))

Next

etc
Dim dummy As Object


Dim chkBox1 As MSForms.CheckBox

chkBox1 = objPage.Controls("CheckBox1")
dummy = chkBox1.Value
If dummy = "true" Then

filter &= " AND [CurrentJob] = 'Yes' "

End If

' nb tried it without the intermediate use of dummy as well to no avail


It all works if used on the form itself in VBscript i.e. connect.returncos
does return the array g_arrCompanies from the .net code.

Thanks in anticipation.

Duncan

I haven't tried it, but if you have some sample code, I'll give it a whack
here.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I am programming a .net based addin for Outlook and want to access the
values
of certain controls on an Outlook Custom Form. These controls are from
FM20.dll, the two in particular causing me grief are the checkBox and
comboBox controls. In vbscript I can access the controls and set their
values happily, but in .net the checkbox.value is returned as an Object
(other properties are returned as their more usual types like boolean,
string etc). In the case of the combobox I am trying to use the .List()
call to assign an array to it, but in .net it seems to expect an Object.
Attempts to CType the variable to an Object result in failure.

Does anyone have any experience of accessing and using controls on
Outlook
forms from .net?

Thanks in anticipation,

Duncan
 
D

Duncan McCreadie

The OutlookViewControls are behaving oddly - when you first load them they
seem to be correct, but when I refresh them with a different restriction
applied the results are inconsistent. Very odd indeed.

Duncan

Sue Mosher said:
Thanks. I can't even get past the ModifiedFormPages statement in VB.Net.
I'll ask around and report back.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Duncan McCreadie said:
Thanks for the offer - here goes:

Create a form (mine is a contactitem) with a combobox and checkbox on. The
code to use them is then something like:
Sub item_Open()

'

' User opened connect.applicationobject.activeinspector.currentitem

'

Dim objPage As Object

Dim itm As Microsoft.Office.Interop.Outlook.ContactItem

Dim ComboBox1 As MSForms.ComboBox ' Company



Dim myInspector As Microsoft.Office.Interop.Outlook.Inspector

Dim strRestrict As String

Dim restricted As Microsoft.Office.Interop.Outlook.Items

Dim i As Integer

On Error Resume Next

objPage =
Connect.applicationObject.ActiveInspector.ModifiedFormPages("General")

' Load list of existing companies

ComboBox1 = objPage.controls("ORGComboBox1")

'ComboBox1.List() = Connect.ReturnCos this is the original code -
connect.returncos returns an array

'The following is an alternative that also fails

For i = 0 To UBound(Connect.g_arrCompanies)

ComboBox1.AddItem(CType(Connect.g_arrCompanies(i), Object))

Next

etc
Dim dummy As Object


Dim chkBox1 As MSForms.CheckBox

chkBox1 = objPage.Controls("CheckBox1")
dummy = chkBox1.Value
If dummy = "true" Then

filter &= " AND [CurrentJob] = 'Yes' "

End If

' nb tried it without the intermediate use of dummy as well to no avail


It all works if used on the form itself in VBscript i.e. connect.returncos
does return the array g_arrCompanies from the .net code.

Thanks in anticipation.

Duncan

Sue Mosher said:
I haven't tried it, but if you have some sample code, I'll give it a whack
here.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I am programming a .net based addin for Outlook and want to access the
values
of certain controls on an Outlook Custom Form. These controls are from
FM20.dll, the two in particular causing me grief are the checkBox and
comboBox controls. In vbscript I can access the controls and set their
values happily, but in .net the checkbox.value is returned as an Object
(other properties are returned as their more usual types like boolean,
string etc). In the case of the combobox I am trying to use the .List()
call to assign an array to it, but in .net it seems to expect an Object.
Attempts to CType the variable to an Object result in failure.

Does anyone have any experience of accessing and using controls on Outlook
forms from .net?

Thanks in anticipation,

Duncan
 
D

Duncan McCreadie

That's as good as it gets I think - but you can then reference controls by
assigning an object to the modifiedformpages object as below:

Public Sub Refresh_Views()

'

' Use ViewControl to select Contacts

Dim objPage As Object

Dim ViewCtl1 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim ViewCtl2 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim ViewCtl3 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim chkBox1 As CheckBox

Dim chkBox2 As CheckBox

Dim filter As String

On Error Resume Next



' First one is previous job holders

objPage = Connect.applicationObject.ActiveInspector.ModifiedFormPages("Job
Details")

chkBox1 = objPage.Controls("CheckBox1")

chkBox2 = objPage.Controls("CheckBox2")

ViewCtl1 = objPage.Controls("OVCtl1")

filter = "[Company] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.CompanyName & """"

filter &= " And [FullName] <> """ &
Connect.applicationObject.ActiveInspector.CurrentItem.FullName & """"

filter &= " And [JobTitle] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.JobTitle & """"

If Len(Connect.applicationObject.ActiveInspector.CurrentItem.Department) <>
0 Then filter &= " And [Department] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.Department & """"

With ViewCtl1

..Folder = "\\contactree\contactree contacts"

..View = "ContacTree JobHolders"

..Restriction = filter

End With

ViewCtl1 = Nothing

'***************************************************************************
*******************************

' ViewControl for contacts in same company and department

'

ViewCtl2 = objPage.Controls("OVCtl2")

filter = "[Company] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.CompanyName & """"

filter &= " And [FullName] <> """ &
Connect.applicationObject.ActiveInspector.CurrentItem.FullName & """"

filter &= " And [MessageClass] = 'IPM.Contact.CTContact' "

If chkBox1.Value = "true" Then

filter &= " AND [CurrentJob] = ""Yes"" "

End If

If chkBox2.Value = "true" Then

filter &= " And [Department] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.Department & """"

End If

With ViewCtl2

..Folder = "\\contactree\contactree contacts"

..View = "ContacTree Dept"

..Restriction = filter

End With

objPage = Nothing

ViewCtl2 = Nothing

chkBox1 = Nothing

chkBox2 = Nothing

The problem I am having with this currently is that the viewcontrols are
getting messed up when I refresh the views (after a change in the checkbox
condition). It is as if the viewcontrols are transposed in memory with
viewctl1 having the filter for viewctl2 applied and vice versa. NB It works
fine on the first pass which makes me wonder if something is staying in
memory and getting corrupted. I have even tried forcing a GarbageCollection
to no effect.

Any further input you can offer, gratefully received,

Duncan
Sue Mosher said:
Doh! Not a waste of time at all! And I even remember having read that
article. Thanks for reminding me about it.

Unfortunately, I still can't get my code to run past the ModifiedFormPages
statement, though. VB.Net shows it as a System.__COMObject type with no
properties even after following all the instructions in the article,
including removing the locally created PIA.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Duncan McCreadie said:
After days of searching, I found this in the Microsoft Support which might
help http://support.microsoft.com/default.aspx?scid=kb;en-us;824009 ! It
turns out I had the wrong one and that's why half the properties were
hidden! Sorry for wasting your time......
Thanks for the offer - here goes:

Create a form (mine is a contactitem) with a combobox and checkbox on.
The
code to use them is then something like:
Sub item_Open()

'

' User opened connect.applicationobject.activeinspector.currentitem

'

Dim objPage As Object

Dim itm As Microsoft.Office.Interop.Outlook.ContactItem

Dim ComboBox1 As MSForms.ComboBox ' Company



Dim myInspector As Microsoft.Office.Interop.Outlook.Inspector

Dim strRestrict As String

Dim restricted As Microsoft.Office.Interop.Outlook.Items

Dim i As Integer

On Error Resume Next

objPage =
Connect.applicationObject.ActiveInspector.ModifiedFormPages("General")

' Load list of existing companies

ComboBox1 = objPage.controls("ORGComboBox1")

'ComboBox1.List() = Connect.ReturnCos this is the original code -
connect.returncos returns an array

'The following is an alternative that also fails

For i = 0 To UBound(Connect.g_arrCompanies)

ComboBox1.AddItem(CType(Connect.g_arrCompanies(i), Object))

Next

etc
Dim dummy As Object


Dim chkBox1 As MSForms.CheckBox

chkBox1 = objPage.Controls("CheckBox1")
dummy = chkBox1.Value
If dummy = "true" Then

filter &= " AND [CurrentJob] = 'Yes' "

End If

' nb tried it without the intermediate use of dummy as well to no avail


It all works if used on the form itself in VBscript i.e. connect.returncos
does return the array g_arrCompanies from the .net code.

Thanks in anticipation.

Duncan

I haven't tried it, but if you have some sample code, I'll give it a
whack
here.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I am programming a .net based addin for Outlook and want to
access
the
values
of certain controls on an Outlook Custom Form. These controls are
from
FM20.dll, the two in particular causing me grief are the
checkBox
and
comboBox controls. In vbscript I can access the controls and set
their
values happily, but in .net the checkbox.value is returned as an
Object
(other properties are returned as their more usual types like boolean,
string etc). In the case of the combobox I am trying to use the
.List()
call to assign an array to it, but in .net it seems to expect an
Object.
Attempts to CType the variable to an Object result in failure.

Does anyone have any experience of accessing and using controls on
Outlook
forms from .net?

Thanks in anticipation,

Duncan
 
S

Sue Mosher [MVP-Outlook]

Thanks. I can't use

chkBox1 = objPage.Controls("CheckBox1")

because I get an error "interface cannot be indexed because it has no
default property" but I can get each control in a For Each loop. The Name
property of the control is available, but I can't set the List property on a
combo box to an array or get the value from a CheckBox (which should be True
or False, BTW, not "True" as your code has it -- could that be part of your
OVC problems?).

Very frustrating.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Duncan McCreadie said:
That's as good as it gets I think - but you can then reference controls by
assigning an object to the modifiedformpages object as below:

Public Sub Refresh_Views()

'

' Use ViewControl to select Contacts

Dim objPage As Object

Dim ViewCtl1 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim ViewCtl2 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim ViewCtl3 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim chkBox1 As CheckBox

Dim chkBox2 As CheckBox

Dim filter As String

On Error Resume Next



' First one is previous job holders

objPage = Connect.applicationObject.ActiveInspector.ModifiedFormPages("Job
Details")

chkBox1 = objPage.Controls("CheckBox1")

chkBox2 = objPage.Controls("CheckBox2")

ViewCtl1 = objPage.Controls("OVCtl1")

filter = "[Company] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.CompanyName & """"

filter &= " And [FullName] <> """ &
Connect.applicationObject.ActiveInspector.CurrentItem.FullName & """"

filter &= " And [JobTitle] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.JobTitle & """"

If Len(Connect.applicationObject.ActiveInspector.CurrentItem.Department)
0 Then filter &= " And [Department] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.Department & """"

With ViewCtl1

.Folder = "\\contactree\contactree contacts"

.View = "ContacTree JobHolders"

.Restriction = filter

End With

ViewCtl1 = Nothing

'***************************************************************************
*******************************

' ViewControl for contacts in same company and department

'

ViewCtl2 = objPage.Controls("OVCtl2")

filter = "[Company] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.CompanyName & """"

filter &= " And [FullName] <> """ &
Connect.applicationObject.ActiveInspector.CurrentItem.FullName & """"

filter &= " And [MessageClass] = 'IPM.Contact.CTContact' "

If chkBox1.Value = "true" Then

filter &= " AND [CurrentJob] = ""Yes"" "

End If

If chkBox2.Value = "true" Then

filter &= " And [Department] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.Department & """"

End If

With ViewCtl2

.Folder = "\\contactree\contactree contacts"

.View = "ContacTree Dept"

.Restriction = filter

End With

objPage = Nothing

ViewCtl2 = Nothing

chkBox1 = Nothing

chkBox2 = Nothing

The problem I am having with this currently is that the viewcontrols are
getting messed up when I refresh the views (after a change in the checkbox
condition). It is as if the viewcontrols are transposed in memory with
viewctl1 having the filter for viewctl2 applied and vice versa. NB It works
fine on the first pass which makes me wonder if something is staying in
memory and getting corrupted. I have even tried forcing a GarbageCollection
to no effect.

Any further input you can offer, gratefully received,

Duncan
Sue Mosher said:
Doh! Not a waste of time at all! And I even remember having read that
article. Thanks for reminding me about it.

Unfortunately, I still can't get my code to run past the ModifiedFormPages
statement, though. VB.Net shows it as a System.__COMObject type with no
properties even after following all the instructions in the article,
including removing the locally created PIA.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Duncan McCreadie said:
After days of searching, I found this in the Microsoft Support which might
help http://support.microsoft.com/default.aspx?scid=kb;en-us;824009 ! It
turns out I had the wrong one and that's why half the properties were
hidden! Sorry for wasting your time......


Thanks for the offer - here goes:

Create a form (mine is a contactitem) with a combobox and checkbox on.
The
code to use them is then something like:
Sub item_Open()

'

' User opened connect.applicationobject.activeinspector.currentitem

'

Dim objPage As Object

Dim itm As Microsoft.Office.Interop.Outlook.ContactItem

Dim ComboBox1 As MSForms.ComboBox ' Company



Dim myInspector As Microsoft.Office.Interop.Outlook.Inspector

Dim strRestrict As String

Dim restricted As Microsoft.Office.Interop.Outlook.Items

Dim i As Integer

On Error Resume Next

objPage =
Connect.applicationObject.ActiveInspector.ModifiedFormPages("General")

' Load list of existing companies

ComboBox1 = objPage.controls("ORGComboBox1")

'ComboBox1.List() = Connect.ReturnCos this is the original code -
connect.returncos returns an array

'The following is an alternative that also fails

For i = 0 To UBound(Connect.g_arrCompanies)

ComboBox1.AddItem(CType(Connect.g_arrCompanies(i), Object))

Next

etc
Dim dummy As Object


Dim chkBox1 As MSForms.CheckBox

chkBox1 = objPage.Controls("CheckBox1")
dummy = chkBox1.Value
If dummy = "true" Then

filter &= " AND [CurrentJob] = 'Yes' "

End If

' nb tried it without the intermediate use of dummy as well to no avail


It all works if used on the form itself in VBscript i.e.
connect.returncos
does return the array g_arrCompanies from the .net code.

Thanks in anticipation.

Duncan

I haven't tried it, but if you have some sample code, I'll give
it
controls
 
D

Duncan McCreadie

Those are the symptoms I had before resetting the Reference to the correct
MS Forms library - after that the checkbox value and list method for the
combobox were available and work.

Although you are right about the value of the checkbox being True/False not
"True", bizarrely it does only select the branch when it is True! The OVC
problems seem unrelated in that I have commented out all the code that
changes the filter dependant on checkbox values and the bizarre behaviour is
still present.

A clue may exist in that I have 3 OVC's in use, one on a separate page, two
together. The two together are corrupting each other but the one on its own
is fine and works "as advertised"!

Duncan
Sue Mosher said:
Thanks. I can't use

chkBox1 = objPage.Controls("CheckBox1")

because I get an error "interface cannot be indexed because it has no
default property" but I can get each control in a For Each loop. The Name
property of the control is available, but I can't set the List property on a
combo box to an array or get the value from a CheckBox (which should be True
or False, BTW, not "True" as your code has it -- could that be part of your
OVC problems?).

Very frustrating.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Duncan McCreadie said:
That's as good as it gets I think - but you can then reference controls by
assigning an object to the modifiedformpages object as below:

Public Sub Refresh_Views()

'

' Use ViewControl to select Contacts

Dim objPage As Object

Dim ViewCtl1 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim ViewCtl2 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim ViewCtl3 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim chkBox1 As CheckBox

Dim chkBox2 As CheckBox

Dim filter As String

On Error Resume Next



' First one is previous job holders

objPage = Connect.applicationObject.ActiveInspector.ModifiedFormPages("Job
Details")

chkBox1 = objPage.Controls("CheckBox1")

chkBox2 = objPage.Controls("CheckBox2")

ViewCtl1 = objPage.Controls("OVCtl1")

filter = "[Company] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.CompanyName & """"

filter &= " And [FullName] <> """ &
Connect.applicationObject.ActiveInspector.CurrentItem.FullName & """"

filter &= " And [JobTitle] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.JobTitle & """"

If Len(Connect.applicationObject.ActiveInspector.CurrentItem.Department)
0 Then filter &= " And [Department] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.Department & """"

With ViewCtl1

.Folder = "\\contactree\contactree contacts"

.View = "ContacTree JobHolders"

.Restriction = filter

End With

ViewCtl1 = Nothing
'***************************************************************************
*******************************

' ViewControl for contacts in same company and department

'

ViewCtl2 = objPage.Controls("OVCtl2")

filter = "[Company] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.CompanyName & """"

filter &= " And [FullName] <> """ &
Connect.applicationObject.ActiveInspector.CurrentItem.FullName & """"

filter &= " And [MessageClass] = 'IPM.Contact.CTContact' "

If chkBox1.Value = "true" Then

filter &= " AND [CurrentJob] = ""Yes"" "

End If

If chkBox2.Value = "true" Then

filter &= " And [Department] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.Department & """"

End If

With ViewCtl2

.Folder = "\\contactree\contactree contacts"

.View = "ContacTree Dept"

.Restriction = filter

End With

objPage = Nothing

ViewCtl2 = Nothing

chkBox1 = Nothing

chkBox2 = Nothing

The problem I am having with this currently is that the viewcontrols are
getting messed up when I refresh the views (after a change in the checkbox
condition). It is as if the viewcontrols are transposed in memory with
viewctl1 having the filter for viewctl2 applied and vice versa. NB It works
fine on the first pass which makes me wonder if something is staying in
memory and getting corrupted. I have even tried forcing a GarbageCollection
to no effect.

Any further input you can offer, gratefully received,

Duncan
Sue Mosher said:
Doh! Not a waste of time at all! And I even remember having read that
article. Thanks for reminding me about it.

Unfortunately, I still can't get my code to run past the ModifiedFormPages
statement, though. VB.Net shows it as a System.__COMObject type with no
properties even after following all the instructions in the article,
including removing the locally created PIA.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



After days of searching, I found this in the Microsoft Support which might
help http://support.microsoft.com/default.aspx?scid=kb;en-us;824009
!
It
turns out I had the wrong one and that's why half the properties were
hidden! Sorry for wasting your time......


Thanks for the offer - here goes:

Create a form (mine is a contactitem) with a combobox and
checkbox
on.
The
code to use them is then something like:
Sub item_Open()

'

' User opened connect.applicationobject.activeinspector.currentitem

'

Dim objPage As Object

Dim itm As Microsoft.Office.Interop.Outlook.ContactItem

Dim ComboBox1 As MSForms.ComboBox ' Company



Dim myInspector As Microsoft.Office.Interop.Outlook.Inspector

Dim strRestrict As String

Dim restricted As Microsoft.Office.Interop.Outlook.Items

Dim i As Integer

On Error Resume Next

objPage =
Connect.applicationObject.ActiveInspector.ModifiedFormPages("General")

' Load list of existing companies

ComboBox1 = objPage.controls("ORGComboBox1")

'ComboBox1.List() = Connect.ReturnCos this is the original code -
connect.returncos returns an array

'The following is an alternative that also fails

For i = 0 To UBound(Connect.g_arrCompanies)

ComboBox1.AddItem(CType(Connect.g_arrCompanies(i), Object))

Next

etc
Dim dummy As Object


Dim chkBox1 As MSForms.CheckBox

chkBox1 = objPage.Controls("CheckBox1")
dummy = chkBox1.Value
If dummy = "true" Then

filter &= " AND [CurrentJob] = 'Yes' "

End If

' nb tried it without the intermediate use of dummy as well to no
avail


It all works if used on the form itself in VBscript i.e.
connect.returncos
does return the array g_arrCompanies from the .net code.

Thanks in anticipation.

Duncan

I haven't tried it, but if you have some sample code, I'll
give
it controls
are and
set
as
expect
an controls
 
D

Duncan McCreadie

One of the other symptoms, is that I cannot get the .Folder property to
change for any of the OVC's which is unhelpful! I have noticed that there
is another OVC library available in
AxMicrosoft.Office.Interop.OutlookViewCtl - should I be using this library
instead?

Duncan
Sue Mosher said:
Thanks. I can't use

chkBox1 = objPage.Controls("CheckBox1")

because I get an error "interface cannot be indexed because it has no
default property" but I can get each control in a For Each loop. The Name
property of the control is available, but I can't set the List property on a
combo box to an array or get the value from a CheckBox (which should be True
or False, BTW, not "True" as your code has it -- could that be part of your
OVC problems?).

Very frustrating.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Duncan McCreadie said:
That's as good as it gets I think - but you can then reference controls by
assigning an object to the modifiedformpages object as below:

Public Sub Refresh_Views()

'

' Use ViewControl to select Contacts

Dim objPage As Object

Dim ViewCtl1 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim ViewCtl2 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim ViewCtl3 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim chkBox1 As CheckBox

Dim chkBox2 As CheckBox

Dim filter As String

On Error Resume Next



' First one is previous job holders

objPage = Connect.applicationObject.ActiveInspector.ModifiedFormPages("Job
Details")

chkBox1 = objPage.Controls("CheckBox1")

chkBox2 = objPage.Controls("CheckBox2")

ViewCtl1 = objPage.Controls("OVCtl1")

filter = "[Company] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.CompanyName & """"

filter &= " And [FullName] <> """ &
Connect.applicationObject.ActiveInspector.CurrentItem.FullName & """"

filter &= " And [JobTitle] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.JobTitle & """"

If Len(Connect.applicationObject.ActiveInspector.CurrentItem.Department)
0 Then filter &= " And [Department] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.Department & """"

With ViewCtl1

.Folder = "\\contactree\contactree contacts"

.View = "ContacTree JobHolders"

.Restriction = filter

End With

ViewCtl1 = Nothing
'***************************************************************************
*******************************

' ViewControl for contacts in same company and department

'

ViewCtl2 = objPage.Controls("OVCtl2")

filter = "[Company] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.CompanyName & """"

filter &= " And [FullName] <> """ &
Connect.applicationObject.ActiveInspector.CurrentItem.FullName & """"

filter &= " And [MessageClass] = 'IPM.Contact.CTContact' "

If chkBox1.Value = "true" Then

filter &= " AND [CurrentJob] = ""Yes"" "

End If

If chkBox2.Value = "true" Then

filter &= " And [Department] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.Department & """"

End If

With ViewCtl2

.Folder = "\\contactree\contactree contacts"

.View = "ContacTree Dept"

.Restriction = filter

End With

objPage = Nothing

ViewCtl2 = Nothing

chkBox1 = Nothing

chkBox2 = Nothing

The problem I am having with this currently is that the viewcontrols are
getting messed up when I refresh the views (after a change in the checkbox
condition). It is as if the viewcontrols are transposed in memory with
viewctl1 having the filter for viewctl2 applied and vice versa. NB It works
fine on the first pass which makes me wonder if something is staying in
memory and getting corrupted. I have even tried forcing a GarbageCollection
to no effect.

Any further input you can offer, gratefully received,

Duncan
Sue Mosher said:
Doh! Not a waste of time at all! And I even remember having read that
article. Thanks for reminding me about it.

Unfortunately, I still can't get my code to run past the ModifiedFormPages
statement, though. VB.Net shows it as a System.__COMObject type with no
properties even after following all the instructions in the article,
including removing the locally created PIA.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



After days of searching, I found this in the Microsoft Support which might
help http://support.microsoft.com/default.aspx?scid=kb;en-us;824009
!
It
turns out I had the wrong one and that's why half the properties were
hidden! Sorry for wasting your time......


Thanks for the offer - here goes:

Create a form (mine is a contactitem) with a combobox and
checkbox
on.
The
code to use them is then something like:
Sub item_Open()

'

' User opened connect.applicationobject.activeinspector.currentitem

'

Dim objPage As Object

Dim itm As Microsoft.Office.Interop.Outlook.ContactItem

Dim ComboBox1 As MSForms.ComboBox ' Company



Dim myInspector As Microsoft.Office.Interop.Outlook.Inspector

Dim strRestrict As String

Dim restricted As Microsoft.Office.Interop.Outlook.Items

Dim i As Integer

On Error Resume Next

objPage =
Connect.applicationObject.ActiveInspector.ModifiedFormPages("General")

' Load list of existing companies

ComboBox1 = objPage.controls("ORGComboBox1")

'ComboBox1.List() = Connect.ReturnCos this is the original code -
connect.returncos returns an array

'The following is an alternative that also fails

For i = 0 To UBound(Connect.g_arrCompanies)

ComboBox1.AddItem(CType(Connect.g_arrCompanies(i), Object))

Next

etc
Dim dummy As Object


Dim chkBox1 As MSForms.CheckBox

chkBox1 = objPage.Controls("CheckBox1")
dummy = chkBox1.Value
If dummy = "true" Then

filter &= " AND [CurrentJob] = 'Yes' "

End If

' nb tried it without the intermediate use of dummy as well to no
avail


It all works if used on the form itself in VBscript i.e.
connect.returncos
does return the array g_arrCompanies from the .net code.

Thanks in anticipation.

Duncan

I haven't tried it, but if you have some sample code, I'll
give
it controls
are and
set
as
expect
an controls
 
S

Sue Mosher [MVP-Outlook]

Well, I got it to work declaring both checkbox and combobox as Object. I set
the combobox with a Ctype and the checkbox without, but they both worked. Go
figure.

I have only one COM reference for the OVC on my OL2003 + .NET development
machine and it points to a PIA at
C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.OutlookViewCtl\11.0.0.0__71
e9bce111e9429c\Microsoft.Office.Interop.OutlookViewCtl.dll

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Duncan McCreadie said:
Those are the symptoms I had before resetting the Reference to the correct
MS Forms library - after that the checkbox value and list method for the
combobox were available and work.

Although you are right about the value of the checkbox being True/False not
"True", bizarrely it does only select the branch when it is True! The OVC
problems seem unrelated in that I have commented out all the code that
changes the filter dependant on checkbox values and the bizarre behaviour is
still present.

A clue may exist in that I have 3 OVC's in use, one on a separate page, two
together. The two together are corrupting each other but the one on its own
is fine and works "as advertised"!

Duncan
Sue Mosher said:
Thanks. I can't use

chkBox1 = objPage.Controls("CheckBox1")

because I get an error "interface cannot be indexed because it has no
default property" but I can get each control in a For Each loop. The Name
property of the control is available, but I can't set the List property
on
a
combo box to an array or get the value from a CheckBox (which should be True
or False, BTW, not "True" as your code has it -- could that be part of your
OVC problems?).
controls
by
assigning an object to the modifiedformpages object as below:

Public Sub Refresh_Views()

'

' Use ViewControl to select Contacts

Dim objPage As Object

Dim ViewCtl1 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim ViewCtl2 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim ViewCtl3 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim chkBox1 As CheckBox

Dim chkBox2 As CheckBox

Dim filter As String

On Error Resume Next



' First one is previous job holders

objPage = Connect.applicationObject.ActiveInspector.ModifiedFormPages("Job
Details")

chkBox1 = objPage.Controls("CheckBox1")

chkBox2 = objPage.Controls("CheckBox2")

ViewCtl1 = objPage.Controls("OVCtl1")

filter = "[Company] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.CompanyName & """"

filter &= " And [FullName] <> """ &
Connect.applicationObject.ActiveInspector.CurrentItem.FullName & """"

filter &= " And [JobTitle] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.JobTitle & """"

If
Len(Connect.applicationObject.ActiveInspector.CurrentItem.Department)
0 Then filter &= " And [Department] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.Department & """"

With ViewCtl1

.Folder = "\\contactree\contactree contacts"

.View = "ContacTree JobHolders"

.Restriction = filter

End With

ViewCtl1 = Nothing
'***************************************************************************
*******************************

' ViewControl for contacts in same company and department

'

ViewCtl2 = objPage.Controls("OVCtl2")

filter = "[Company] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.CompanyName & """"

filter &= " And [FullName] <> """ &
Connect.applicationObject.ActiveInspector.CurrentItem.FullName & """"

filter &= " And [MessageClass] = 'IPM.Contact.CTContact' "

If chkBox1.Value = "true" Then

filter &= " AND [CurrentJob] = ""Yes"" "

End If

If chkBox2.Value = "true" Then

filter &= " And [Department] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.Department & """"

End If

With ViewCtl2

.Folder = "\\contactree\contactree contacts"

.View = "ContacTree Dept"

.Restriction = filter

End With

objPage = Nothing

ViewCtl2 = Nothing

chkBox1 = Nothing

chkBox2 = Nothing

The problem I am having with this currently is that the viewcontrols are
getting messed up when I refresh the views (after a change in the checkbox
condition). It is as if the viewcontrols are transposed in memory with
viewctl1 having the filter for viewctl2 applied and vice versa. NB It works
fine on the first pass which makes me wonder if something is staying in
memory and getting corrupted. I have even tried forcing a GarbageCollection
to no effect.

Any further input you can offer, gratefully received,

Duncan


After days of searching, I found this in the Microsoft Support which
might
help
http://support.microsoft.com/default.aspx?scid=kb;en-us;824009
!
It
turns out I had the wrong one and that's why half the properties were
hidden! Sorry for wasting your time......


Thanks for the offer - here goes:

Create a form (mine is a contactitem) with a combobox and checkbox
on.
The
code to use them is then something like:
Sub item_Open()

'

' User opened connect.applicationobject.activeinspector.currentitem

'

Dim objPage As Object

Dim itm As Microsoft.Office.Interop.Outlook.ContactItem

Dim ComboBox1 As MSForms.ComboBox ' Company



Dim myInspector As Microsoft.Office.Interop.Outlook.Inspector

Dim strRestrict As String

Dim restricted As Microsoft.Office.Interop.Outlook.Items

Dim i As Integer

On Error Resume Next

objPage =

Connect.applicationObject.ActiveInspector.ModifiedFormPages("General")

' Load list of existing companies

ComboBox1 = objPage.controls("ORGComboBox1")

'ComboBox1.List() = Connect.ReturnCos this is the original code -
connect.returncos returns an array

'The following is an alternative that also fails

For i = 0 To UBound(Connect.g_arrCompanies)

ComboBox1.AddItem(CType(Connect.g_arrCompanies(i), Object))

Next

etc
Dim dummy As Object


Dim chkBox1 As MSForms.CheckBox

chkBox1 = objPage.Controls("CheckBox1")
dummy = chkBox1.Value
If dummy = "true" Then

filter &= " AND [CurrentJob] = 'Yes' "

End If

' nb tried it without the intermediate use of dummy as well to no
avail


It all works if used on the form itself in VBscript i.e.
connect.returncos
does return the array g_arrCompanies from the .net code.

Thanks in anticipation.

Duncan

I haven't tried it, but if you have some sample code, I'll
give
it
a
whack
here.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I am programming a .net based addin for Outlook and want to
access
the
values
of certain controls on an Outlook Custom Form. These controls
are
from
FM20.dll, the two in particular causing me grief are the
checkBox
and
comboBox controls. In vbscript I can access the controls and
set
their
values happily, but in .net the checkbox.value is returned
as
an
Object
(other properties are returned as their more usual types like
boolean,
string etc). In the case of the combobox I am trying to
use
the
.List()
call to assign an array to it, but in .net it seems to
expect
an
Object.
Attempts to CType the variable to an Object result in failure.

Does anyone have any experience of accessing and using controls
on
Outlook
forms from .net?

Thanks in anticipation,

Duncan
 
D

Duncan McCreadie

The second reference appeared when I added an OVC to a Windows Form - it was
as if it needed a different interop to work on a windows form?

Duncan

Sue Mosher said:
Well, I got it to work declaring both checkbox and combobox as Object. I set
the combobox with a Ctype and the checkbox without, but they both worked. Go
figure.

I have only one COM reference for the OVC on my OL2003 + .NET development
machine and it points to a PIA at
C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.OutlookViewCtl\11.0.0.0__71
e9bce111e9429c\Microsoft.Office.Interop.OutlookViewCtl.dll

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Duncan McCreadie said:
Those are the symptoms I had before resetting the Reference to the correct
MS Forms library - after that the checkbox value and list method for the
combobox were available and work.

Although you are right about the value of the checkbox being True/False not
"True", bizarrely it does only select the branch when it is True! The OVC
problems seem unrelated in that I have commented out all the code that
changes the filter dependant on checkbox values and the bizarre
behaviour
is
still present.

A clue may exist in that I have 3 OVC's in use, one on a separate page, two
together. The two together are corrupting each other but the one on its own
is fine and works "as advertised"!

Duncan
property
on
a
combo box to an array or get the value from a CheckBox (which should
be
True
or False, BTW, not "True" as your code has it -- could that be part of your
OVC problems?).

That's as good as it gets I think - but you can then reference
controls
by
assigning an object to the modifiedformpages object as below:

Public Sub Refresh_Views()

'

' Use ViewControl to select Contacts

Dim objPage As Object

Dim ViewCtl1 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim ViewCtl2 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim ViewCtl3 As Microsoft.Office.Interop.OutlookViewCtl.ViewCtl

Dim chkBox1 As CheckBox

Dim chkBox2 As CheckBox

Dim filter As String

On Error Resume Next



' First one is previous job holders

objPage = Connect.applicationObject.ActiveInspector.ModifiedFormPages("Job
Details")

chkBox1 = objPage.Controls("CheckBox1")

chkBox2 = objPage.Controls("CheckBox2")

ViewCtl1 = objPage.Controls("OVCtl1")

filter = "[Company] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.CompanyName & """"

filter &= " And [FullName] <> """ &
Connect.applicationObject.ActiveInspector.CurrentItem.FullName & """"

filter &= " And [JobTitle] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.JobTitle & """"

If Len(Connect.applicationObject.ActiveInspector.CurrentItem.Department)
<>
0 Then filter &= " And [Department] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.Department & """"

With ViewCtl1

.Folder = "\\contactree\contactree contacts"

.View = "ContacTree JobHolders"

.Restriction = filter

End With

ViewCtl1 = Nothing
'***************************************************************************
*******************************

' ViewControl for contacts in same company and department

'

ViewCtl2 = objPage.Controls("OVCtl2")

filter = "[Company] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.CompanyName & """"

filter &= " And [FullName] <> """ &
Connect.applicationObject.ActiveInspector.CurrentItem.FullName & """"

filter &= " And [MessageClass] = 'IPM.Contact.CTContact' "

If chkBox1.Value = "true" Then

filter &= " AND [CurrentJob] = ""Yes"" "

End If

If chkBox2.Value = "true" Then

filter &= " And [Department] = """ &
Connect.applicationObject.ActiveInspector.CurrentItem.Department & """"

End If

With ViewCtl2

.Folder = "\\contactree\contactree contacts"

.View = "ContacTree Dept"

.Restriction = filter

End With

objPage = Nothing

ViewCtl2 = Nothing

chkBox1 = Nothing

chkBox2 = Nothing

The problem I am having with this currently is that the viewcontrols are
getting messed up when I refresh the views (after a change in the checkbox
condition). It is as if the viewcontrols are transposed in memory with
viewctl1 having the filter for viewctl2 applied and vice versa. NB It
works
fine on the first pass which makes me wonder if something is staying in
memory and getting corrupted. I have even tried forcing a
GarbageCollection
to no effect.

Any further input you can offer, gratefully received,

Duncan


After days of searching, I found this in the Microsoft Support which
might
help
http://support.microsoft.com/default.aspx?scid=kb;en-us;824009
!
It
turns out I had the wrong one and that's why half the properties were
hidden! Sorry for wasting your time......


Thanks for the offer - here goes:

Create a form (mine is a contactitem) with a combobox and checkbox
on.
The
code to use them is then something like:
Sub item_Open()

'

' User opened
connect.applicationobject.activeinspector.currentitem

'

Dim objPage As Object

Dim itm As Microsoft.Office.Interop.Outlook.ContactItem

Dim ComboBox1 As MSForms.ComboBox ' Company



Dim myInspector As Microsoft.Office.Interop.Outlook.Inspector

Dim strRestrict As String

Dim restricted As Microsoft.Office.Interop.Outlook.Items

Dim i As Integer

On Error Resume Next

objPage =

Connect.applicationObject.ActiveInspector.ModifiedFormPages("General")

' Load list of existing companies

ComboBox1 = objPage.controls("ORGComboBox1")

'ComboBox1.List() = Connect.ReturnCos this is the original code -
connect.returncos returns an array

'The following is an alternative that also fails

For i = 0 To UBound(Connect.g_arrCompanies)

ComboBox1.AddItem(CType(Connect.g_arrCompanies(i), Object))

Next

etc
Dim dummy As Object


Dim chkBox1 As MSForms.CheckBox

chkBox1 = objPage.Controls("CheckBox1")
dummy = chkBox1.Value
If dummy = "true" Then

filter &= " AND [CurrentJob] = 'Yes' "

End If

' nb tried it without the intermediate use of dummy as well
to
no
avail


It all works if used on the form itself in VBscript i.e.
connect.returncos
does return the array g_arrCompanies from the .net code.

Thanks in anticipation.

Duncan

message
I haven't tried it, but if you have some sample code, I'll give
it
a
whack
here.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I am programming a .net based addin for Outlook and want to
access
the
values
of certain controls on an Outlook Custom Form. These controls
are
from
FM20.dll, the two in particular causing me grief are the
checkBox
and
comboBox controls. In vbscript I can access the
controls
and
set
their
values happily, but in .net the checkbox.value is
returned
as
an
Object
(other properties are returned as their more usual types like
boolean,
string etc). In the case of the combobox I am trying to use
the
.List()
call to assign an array to it, but in .net it seems to expect
an
Object.
Attempts to CType the variable to an Object result in failure.

Does anyone have any experience of accessing and using
controls
on
Outlook
forms from .net?

Thanks in anticipation,

Duncan
 

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