CommandButton

S

Simon

Hi

I have a customized form in my Outlook contacts with an
additional page where I added a ComboBox with the
following code:

Sub Item_Open
' Set the NameSpace object
Set objOLNS = Application.GetNameSpace("MAPI")

' Set the Contacts folder, which is in the MAPI
NameSpace
Set objContactFolder = objOLNS.Folders("Public
Folders"). _
Folders("All Public Folders"). _
Folders("Contacts"). _
Folders("Administration")

' Set the collection of all Contact items
Set objAllContacts = objContactFolder.Items

' Set the object referring to the form page the
combo box is on
Set objFormTab =
Item.GetInspector.ModifiedFormPages("MFO - Related
Contacts")

' Set the object referring to the combo box
Set objCombo = objFormTab.Controls("Contact1")

' Loop through all of the contacts
For Each Contact in objAllContacts

' Add the current contact's full name to the
combo box
'objCombo.AddItem Contact.FileAs
objCombo.AddItem Contact.FullName
Next

End Sub

This code adds all contacts in my Public Folder (certain
subfolder - see above) into the ComboBox. This works fine
and I can select any contact I want to.

Now, I would like to add a CommandButton to this form
which has the following function:

If you push the button of the previous selected contact
in the ComboBox the contact is displayed in a new contact
form (Basically the same functionality as if you open a
contact in you contact when you double click on it and
the contact is shown in a form).

I couldn't figure it out how I could code this
functionality. Could you please help me?

Thank you very much in advance.

Regards

Simon
 
K

Ken Slovak - [MVP - Outlook]

In your button's Click event handler:
'get combo as objCombo first
strName = objCombo.Value
Set objContact = objAllContacts.Find("[FullName] = " & Chr(34) & strName & _
Chr(34) )
objContact.Display
 
S

Simon

Hi Ken

Thank you very much for your fast reply.

I have tried your code but I don't get it to work yet.

I added the row Dim Contact1 As objCombo to your code.

Sub Open1_Click
'get combo as objCombo first
Dim Contact1 As objCombo
strName = objCombo.Value
Set objCombo = objAllContacts.Find("[FullName] = " & Chr
(34) & strName & _
Chr(34) )
objCombo.Display
End Sub

I haven't changed anything in the code before this
statement:

Sub Item_Open
' Set the NameSpace object
Set objOLNS = Application.GetNameSpace("MAPI")

' Set the Contacts folder, which is in the MAPI
NameSpace
Set objContactFolder = objOLNS.Folders("Public
Folders"). _
Folders("All Public Folders"). _
Folders("Contacts"). _
Folders("Administration")

' Set the collection of all Contact items
Set objAllContacts = objContactFolder.Items

' Set the object referring to the form page the
combo box is on
Set objFormTab =
Item.GetInspector.ModifiedFormPages("MFO - Related
Contacts")

' Set the object referring to the combo box
Set objCombo = objFormTab.Controls("Contact1")

' Loop through all of the contacts
For Each Contact in objAllContacts

' Add the current contact's full name to the
combo box
'objCombo.AddItem Contact.FileAs
objCombo.AddItem Contact.FullName
Next

End Sub

Could you please have a second look, please?

Thank you very much in advance.

Regards

Simon



-----Original Message-----
In your button's Click event handler:
'get combo as objCombo first
strName = objCombo.Value
Set objContact = objAllContacts.Find("[FullName] = " & Chr(34) & strName & _
Chr(34) )
objContact.Display




Hi

I have a customized form in my Outlook contacts with an
additional page where I added a ComboBox with the
following code:

Sub Item_Open
' Set the NameSpace object
Set objOLNS = Application.GetNameSpace("MAPI")

' Set the Contacts folder, which is in the MAPI
NameSpace
Set objContactFolder = objOLNS.Folders("Public
Folders"). _
Folders("All Public Folders"). _
Folders("Contacts"). _
Folders("Administration")

' Set the collection of all Contact items
Set objAllContacts = objContactFolder.Items

' Set the object referring to the form page the
combo box is on
Set objFormTab =
Item.GetInspector.ModifiedFormPages("MFO - Related
Contacts")

' Set the object referring to the combo box
Set objCombo = objFormTab.Controls("Contact1")

' Loop through all of the contacts
For Each Contact in objAllContacts

' Add the current contact's full name to the
combo box
'objCombo.AddItem Contact.FileAs
objCombo.AddItem Contact.FullName
Next

End Sub

This code adds all contacts in my Public Folder (certain
subfolder - see above) into the ComboBox. This works fine
and I can select any contact I want to.

Now, I would like to add a CommandButton to this form
which has the following function:

If you push the button of the previous selected contact
in the ComboBox the contact is displayed in a new contact
form (Basically the same functionality as if you open a
contact in you contact when you double click on it and
the contact is shown in a form).

I couldn't figure it out how I could code this
functionality. Could you please help me?

Thank you very much in advance.

Regards

Simon


.
 
K

Ken Slovak - [MVP - Outlook]

In the Click event handler you need to get the combo box as a control object
just as you did in the Item_Open code. Then you can read the contents of
that control. You also can't use an As clause in VBScript code. You also
cannot display a combo box.

Sub Open1_Click
Dim objCombo
Dim objFormTab
Dim Contact1 'As objCombo
'get combo as objCombo first
Set objFormTab = _
Item.GetInspector.ModifiedFormPages("MFO - Related Contacts")

' Set the object referring to the combo box
Set objCombo = objFormTab.Controls("Contact1")

strName = objCombo.Value
Set Contact1 = objAllContacts.Find("[FullName] = " & _
Chr(34) & strName & Chr(34) )
Contact1.Display
End Sub
 

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