How to Access the "To" Recipient field and update it in outlook form

V

Venkat M

Hi,
I am having problem with vb script in outlook form.....
I want to access the To Recipient field in the outlook form inorder to
change the recipient email everytime whenever a particular box is
checked...I hope someone would help me by providing the command vb code
for this?

Thanks in advance,
Venkat


*** Sent via Developersdex http://www.developersdex.com ***
 
V

Venkat M

Thanks for the reply...
To be more clear, I am basically designing a form with some checkboxes
and some info like company name, product name etc.,....that will be sent
to different persons.
when user selects the checkbox corresponding to a particular product
then the Recipient control box,which would be besides the 'To' user
field, should automatically include the specific email address from
contacts rather than user clicking 'To' box and then selecting recipient
from the address book.
The recipient mail address has to change each time user clicks a
different checkbox....i need command for this to include inside:
Sub checkbox1_Click
???
????
End Sub
Sub checkbox2_Click
???
????
End Sub

I know that if its a simple user defined box, i can edit it using
something like: mypage.controls("checkbox11").Text="(e-mail address removed)"
but we cannot do that for mail field as it is recipient type and not
text type. so i think there is different command for such mail fields!!

I am not trying to replace recipients, just updating it each time....
and actually after this is done, i will have to add another recipient
for one of the checkboxes...that is second step

I look forward for your suggestions.

Thank You very much for your time and help,
Venkat


*** Sent via Developersdex http://www.developersdex.com ***
 
V

Venkat M

Thanks for the reply...
To be more clear, I am basically designing a form with some checkboxes
and some info like company name, product name etc.,....that will be sent
to different persons.
when user selects the checkbox corresponding to a particular product
then the Recipient control box,which would be besides the 'To' user
field, should automatically include the specific email address from
contacts rather than user clicking 'To' box and then selecting recipient
from the address book.
The recipient mail address has to change each time user clicks a
different checkbox....i need command for this to include inside:
Sub checkbox1_Click
???
????
End Sub
Sub checkbox2_Click
???
????
End Sub

I know that if its a simple user defined box, i can edit it using
something like: mypage.controls("checkbox11").Text="(e-mail address removed)"
but we cannot do that for mail field as it is recipient type and not
text type. so i think there is different command for such mail fields!!

I am not trying to replace recipients, just updating it each time....
and actually after this is done, i will have to add another recipient
for one of the checkboxes...that is second step

I look forward for your suggestions.

Thank You very much for your time and help,
Venkat


*** Sent via Developersdex http://www.developersdex.com ***
 
S

Sue Mosher [MVP-Outlook]

In that case, you'd use the Item.Recipients.Add method, which you can look up
in Outlook VBA Help, to add the address to the existing recipients.

To make it really elegant, you may also want to code the reverse process --
iterate the Recipients collection when the user unchecks the box and remove
the recipient with the particular address.
 
V

Venkat M

Thank You very much sue...that works perfectly till adding...I was able
to write the loop when user unchecks the box, but i couldn't know which
command to use to clear... Item.Recipients.Remove is giving an error-
after i run the form and deselect the checkbox the error message is
"Type mismatch 'Item.Recipients.Remove'" This is my code, could you
please check it once....
Dim x
Dim n
x=1
n=1
Sub checkbox13_click()
Set MyPage=Item.GetInspector.ModifiedFormPages("Message")
If x=1 Then
x=x+1
MyPage.Controls("CheckBox15").Locked = true
MyPage.Controls("CheckBox12").Locked = true
MyPage.Controls("CheckBox14").Locked = true
Item.Recipients.Add("(e-mail address removed)")
Else
If x= 2*n Then
Set MyPage=Item.GetInspector.ModifiedFormPages("Message")
MyPage.Controls("CheckBox15").Locked = false
MyPage.Controls("CheckBox12").Locked = false
MyPage.Controls("CheckBox14").Locked = false
n=n+1
x=x+1
Item.Recipients.Remove("(e-mail address removed)")
Else
Set MyPage=Item.GetInspector.ModifiedFormPages("Message")
MyPage.Controls("CheckBox15").Locked = true
MyPage.Controls("CheckBox12").Locked = true
MyPage.Controls("CheckBox14").Locked = true
x=x+1
Item.Recipients.Add("(e-mail address removed)")
End If
End If
End Sub


I have tried using Delete and Resolve in place of Remove..but same
error...do you have any suggestions in this regard?

Thank You for your help,
Venkat


*** Sent via Developersdex http://www.developersdex.com ***
 
V

Venkat M

Thank You very much sue...that works perfectly till adding...I was able
to write the loop when user unchecks the box, but i couldn't know which
command to use to clear... Item.Recipients.Remove is giving an error-
after i run the form and deselect the checkbox the error message is
"Type mismatch 'Item.Recipients.Remove'" This is my code, could you
please check it once....
Dim x
Dim n
x=1
n=1
Sub checkbox13_click()
Set MyPage=Item.GetInspector.ModifiedFormPages("Message")
If x=1 Then
x=x+1
MyPage.Controls("CheckBox15").Locked = true
MyPage.Controls("CheckBox12").Locked = true
MyPage.Controls("CheckBox14").Locked = true
Item.Recipients.Add("(e-mail address removed)")
Else
If x= 2*n Then
Set MyPage=Item.GetInspector.ModifiedFormPages("Message")
MyPage.Controls("CheckBox15").Locked = false
MyPage.Controls("CheckBox12").Locked = false
MyPage.Controls("CheckBox14").Locked = false
n=n+1
x=x+1
Item.Recipients.Remove("(e-mail address removed)")
Else
Set MyPage=Item.GetInspector.ModifiedFormPages("Message")
MyPage.Controls("CheckBox15").Locked = true
MyPage.Controls("CheckBox12").Locked = true
MyPage.Controls("CheckBox14").Locked = true
x=x+1
Item.Recipients.Add("(e-mail address removed)")
End If
End If
End Sub


I have tried using Delete and Resolve in place of Remove..but same
error...do you have any suggestions in this regard?

Thank You for your help,
Venkat



*** Sent via Developersdex http://www.developersdex.com ***
 
S

Sue Mosher [MVP-Outlook]

If you read the Help topics on the Remove and Delete methods, you'd see that
neither can be used with an address as a parameter. Instead, you should
iterate the Recipients collection, check the value of each Recipient.Address
property, and when you find a match, call Recipient.Delete.
 
V

Venkat M

Thank You very much, that was perfect. But after i run the form and
after filling up all the fields, i am not able to send it, it says "a
field on this form requires a value"
I have tried it many times making sure that i didn't miss any field, but
still same error when i try to send the form....
Could you help me if you have any idea what might be going wrong?

Thanks again for your time,
Venkat



*** Sent via Developersdex http://www.developersdex.com ***
 
V

Venkat M

Thank You very much, that was perfect. But after i run the form and
after filling up all the fields, i am not able to send it, it says "a
field on this form requires a value"
I have tried it many times making sure that i didn't miss any field, but
still same error when i try to send the form....
Could you help me if you have any idea what might be going wrong?

Thanks again for your time,
Venkat





*** Sent via Developersdex http://www.developersdex.com ***
 
S

Sue Mosher [MVP-Outlook]

You may want to start a new discussion on that topic, as it sounds unrelated.
The most likely cause is that you had a field on the form that required
validation, but then removed the control without first removing the
validation.
 
V

Venkat M

Thank You sue, I was able to figure that out..i had to delete a field in
the All fields column whose control was previously deleted but field was
there...

Thank You so much for your quick responses and for all your time and
help and for bearing with me:)...




*** Sent via Developersdex http://www.developersdex.com ***
 

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