Load a recipient based on a value in a combo box

C

Clueless

I have a custom Outlook 2007 form that I need help with writing code to
perform the following.

I have two Drop Down boxes: Box 1. person - responsibility Box 2. location
- person

When a certain person is selected in the 1st. Box I want the person's name
to automatically load as a recipient of the email. I would also like to be
able to add an additional name as a recipients to the same email when Box 2.
Has a location and person selected. I use the following code to fill in a
recipient based on a click event but I am not sure how to do an event based
on the value in a drop down box

Sub CommandButton2_Click()
Recipients.Add "Doe, John"
Recipients.ResolveAll
Recipients.Add "Smith, Bill"
Recipients.ResolveAll
End Sub


Thanks In advance
 
C

Clueless

Sue,

The control is bound, I used the Item PropertyChange (ByVal name)

The following code would put John Doe has the recipent but it kept doing it
multiple times until outlook locked up. I want the recipient to be add just
once or removed and changed based on the My.Control.Value. in my Combo Box.

Sub Item_PropertyChange(ByVal Name)
Set MyPage = Item.GetInspector.ModifiedFormPages("Requisition Form")
Set MyControl = MyPage.Controls("ComboBox24")
If Right(MyControl.Value,1) = "e" Then
Set Recipient = Recipients.Add ("Doe, John")
Recipient.Type = 1
Recipients.ResolveAll
End If

End Sub

What am I missing?

Thanks
 
S

Sue Mosher [MVP]

Please look again at the sample code on the page I suggested. It shows how
to run code only on a change to the property you're interested in, not all
properties.

Also, if the control is bound, your code should work with the property
value, not the control value. And I suspect it's bound to a custom property,
not a standard property, which means you need to use the
CustomPropertyChange event.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
C

Clueless

Sue,

You were correct I was not understanding the code correctly but I do have it
working from your instructions. However, I am trying to use the change
property values event but want it to also to occur based on a check box
click even. for example.

If the check box is true when the change property values occurs nothing
happens but once the checkbox is clicked the change properties value then is
initiated. I can't seem to nest the events. What I have below only occurs
after the box is clicked and then I go back and select the drop down box
again. Thanks in advance

ub Item_CustomPropertyChange(ByVal Name)
Set MyPage = Item.GetInspector.ModifiedFormPages("Requisition Form")
Set MyControl = MyPage.Controls("CheckBox14")
If MyControl.Value = True then
Select Case Name
Case "Vendor"
strMyProp1 = Item.UserProperties("Vendor")
Select Case Right(strMyProp1,1)
Case "n"
Set Recipient = Recipients.Add ("Doe, John")
Recipient.Type = 1
Recipients.ResolveAll

End Select
Select Case Right(strMyProp1,1)
Case "g"
Set Recipient = Recipients.Add ("Wilson, greg")
Recipient.Type = 1
Recipients.ResolveAll
End Select

Select Case Right(strMyProp1,1)
Case "r"
Set Recipient = Recipients.Add ("Ross, Mike")
Recipient.Type = 1
Recipients.ResolveAll
End Select

End Select

End If
End Sub
 
S

Sue Mosher [MVP]

Is the check box bound or unbound? If bound, to what property? Is Vendor the
name of the property bound to the combo box with the list of names in it?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
C

Clueless

Sue,

I was able to figure it out based on your examples in your link.

My new issues is that I have created a custom form with check boxes that
display names in the recipient field when selected. When I run the form all
the code works as I need, but if some one receives the form and forwards to
someone else the code will not longer activate. I did not have this issue
with Outlook 2003, but when I went to 2007 and recreated my form I could nt
get it to work like Outlook 2003.

Outlook 2003 tool bar allowed anyone to access the form in the
organizational library then edit the form before sending. The receiver of the
outlook 2003 for coudl then go to tool bars, forms, run this form then send
it to the next person for review. How can I get this to work in outlook 2007,
it does not seem to give the same option as 2003. Please help or gving me
some reading to understadn what I need to do.

Thanks for all your help
 
S

Sue Mosher [MVP]

It sounds like your form is not properly published to the Organizational
Forms library with the "send form definition with item" box unchecked. Only
properly published forms can run code. See
http://www.outlookcode.com/article.aspx?id=61?

Also, the Forward action on the form design's Actions page needs to point to
the published form.
 

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