populating the recipient address in outlook

T

thomas donino

Hello,
I have a form with 4 checkboxes (night add more) that have email addresses.
I cant sort out how to determine which ones are checked to write them into
the recipient area. My thought was to set a variable, the say if #1 is
checked write it to the variable and if the second is checked add it to the
variable or if nothing check # 3 etc etc etc. Am I on the right course? Is
there a more efficient way to code this?

Thank you
 
J

Jacob Skaria

Hi Thomas

Try this code. No matter how many checkboxes are there the loop collects all
receipients which are checked to a string variable

Dim Ctrl As MSForms.Control
Dim strReceipients as String
For Each Ctrl In Me.Controls
If TypeOf Ctrl Is MSForms.CheckBox Then
If Ctrl.Object.Value = True Then
strReceipients = strReceipients & ";" & Ctrl.Caption
End If
End If
Next
MsgBox Mid(strReceipients, 2)

If this post helps click Yes
 
T

thomas donino

The code is breaking on the Me.Controls line
Do I need to reference the actual form name in the code?
 
J

Jacob Skaria

I tried this from a commandbutton click and hence used Me.Controls . You can
refer the form name instead like UserForm1.Controls

If this post helps click Yes
 
T

thomas donino

Jacob,

Thank you, its working great now

Tom

Jacob Skaria said:
I tried this from a commandbutton click and hence used Me.Controls . You can
refer the form name instead like UserForm1.Controls

If this post helps click Yes
 
T

thomas donino

I have other checkboxes on the form that are not email addresses. How do i
differentiate them? Should I change those to radio buttons?
 
J

Jacob Skaria

Added one more check to check whether the caption is a mail id

Dim Ctrl As MSForms.Control
Dim strReceipients as String
For Each Ctrl In Me.Controls
If TypeOf Ctrl Is MSForms.CheckBox Then
If Ctrl.Object.Value = True Then
If Instr(Ctrl.Caption,"@")> 0 Then
strReceipients = strReceipients & ";" & Ctrl.Caption
End If
End If
End If
Next
MsgBox Mid(strReceipients, 2)

If this post helps click Yes
 

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