SendObject acSendNoObject Selecting Emails and Outlook

B

b_a_redman

Hi,
What i have is a list box that displays two fields from my table, it
displays a name of a charity and their email address. This list box allows
me to select multiple values. I have a command button with no function. What
i want to happen is when i click on the button, it will take the email
addresses of the charitys selected and populate the To: field in Microsoft
Outlook. People have been referring me to websites and i am just not gettin
the idea of things. Can someone please post the code for this?

Table and form name = Charities
List box name = List1
Field Name in list box = Name of Charity and Email
Command button name = Command1
 
P

Peter Hibbs

Try the code below. I am assuming that in your list box you have two
columns and the second one shows the e-mail address.


Private Sub Command1_Click()

Dim vItem As Variant
Dim vEMail As String, vSubject As String, vText As String

On Error GoTo ErrorHandler

vEMail = ""
For Each vItem In List1.ItemsSelected 'output selected lines
vEMail = vEMail & List1.Column(1, vItem) & ";"
List1.Selected(vItem) = False
Next vItem
vEMail = Left(vEMail, Len(vEMail) - 1)
vSubject = "Subject of e-mail"
vText = "Text of e-mail"
DoCmd.SendObject , , "EMail", , , vEMail, vSubject, vText
Exit Sub

ErrorHandler:
If Err = 2501 Then Exit Sub
Beep
MsgBox Err.Description

End Sub


Paste the code into your button click event so it looks like this.
Watch out for line wrapping. Note that I have used the BCC: parameter
for the e-mail addresses so that the recipients cannot see who else
received the e-mail. If you want them in the To: field then move the
vEMail variable to the parameter immdiately after the "EMail"
parameter.

HTH

Peter Hibbs.
 
B

b_a_redman

I have pasted the code into the button, but when i click on it, it is asking
for an object, it says 'Object Required', how do i correct this?
 
P

Peter Hibbs

I don't know, it works fine on my test form.

At what point do you get the error message? If it is on the
DoCmd.SendObject line, what is in the vEMail variable. Which version
of Access and Outlook are you using.

Peter Hibbs.
 
B

b_a_redman

Im running on Microsoft Office 2003. I select the the emails i want form the
combo box, and then click the button, thats when the 'Object Required'
appears. I then tried to have a look at it myself, i changed the first part
of that line to DoCmd.SendObject acSendNoObject, but it is still asking for
it. So i hcnaged it back and still unchanged. What is the object it is asking
for, would that be an attachemtn for an email?
 
B

b_a_redman

Ok sorry, i found the error, i got past that one, ok now i got another one.
The button comepltes running, but when i select more then one email, it comes
up with 'Unknown Message Recepients, the message was not sent', when one is
selected, a html email message appears but with no address in the field with
'the message was not sent' at the top.
 
P

Peter Hibbs

I have no idea what Object it is asking for. If you Rem out the On
Error line does it come up with an error. I would suggest you try the
DoCmd.SendObject on its own and get that working first with actual
text - something like -

DoCmd.SendObject , , "EMail", , , "YourEMailAddress", "Test","Test"

If that doesn't work then there is something basically wrong with your
set up. Also I presume you mean List Box when you said Combo Box.

We are just being hit by a thunderstorm here in the southern UK so I
am switching off my PC for a bit, if anyone else has any thoughts then
feel free to add them.

Peter Hibbs.
 
B

b_a_redman

ok sorry again, i have corrrected that error, for starters i changed the
column number, i forgot to change that back, and the email address was not
comin over because it was in the BCC column, when i moved it into the To
column, it was shown, why is that?
 
P

Peter Hibbs

Sorry, I'm not sure what the problem is now. Could you give more
details.

Peter Hibbs.
 

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