link between combo box and command button

L

Lauren B

I have a combo-box with 5 names in the drop down menu. When a name is
selected, I want my user to be able to click a command button that will open
an e-mail to that individual. I am attempting to write the code that will
perform this function. I tried the following:

If Me.Name = Name1 Then DoCmd.SendObject , , , "E-mail Address1"

This works for the first entry, but not for all five.

If Me.Name = Name1 Then DoCmd.SendObject , , , "E-mail Address1"
If Me.Name = Name2 Then DoCmd.SendObject , , , "E-mail Address2"
If Me.Name = Name3 Then DoCmd.SendObject , , , "E-mail Address3"
If Me.Name = Name4 Then DoCmd.SendObject , , , "E-mail Address4"
If Me.Name = Name5 Then DoCmd.SendObject , , , "E-mail Address5"

How can I write my code so that an e-mail will open when the command button
is clicked based on the name in the combo box?

Thank you in advance for any assistance.

LB
 
R

Rob Oldfield

Modify the row source of the combo so that the underlying query has names in
the first column, and mail addresses in the second. Then your click code
just needs something like...

DoCmd.SendObject , , , me.cboName.columns(1)

(the columns collection starts at 0, so second column is column number 1)
 

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