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