Sending emai via access form | Member | | Join Date: Oct 2006
Posts: 106
| | |
Let say I have a form (MS Access) with the list of people and their email addresses and a text field which I can write my message.
I have button that when I press the button I want it to send email to all email adressess in this form.
Is this possible.
Or there is a better way of doing this, please help.
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form Quote:
Originally Posted by tara99 Let say I have a form (MS Access) with the list of people and their email addresses and a text field which I can write my message.
I have button that when I press the button I want it to send email to all email adressess in this form.
Is this possible.
Or there is a better way of doing this, please help. Do you want to send the message to everyone in the list or only those selected?
| | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form Quote:
Originally Posted by mmccarthy Do you want to send the message to everyone in the list or only those selected? Thank you for your help
The selected ones
The one I have availabe in the form becuase I run qurey on the backgroud which only displayes those emails I need.
Thanks
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form
Sorry Tara
I understood from your first post that these people were in a list. Are they just separate records on the form and therefore the list is based on the query behind the record source of the form? Quote:
Originally Posted by tara99 Thank you for your help
The selected ones
The one I have availabe in the form becuase I run qurey on the backgroud which only displayes those emails I need.
Thanks | | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form Quote:
Originally Posted by mmccarthy Sorry Tara
I understood from your first post that these people were in a list. Are they just separate records on the form and therefore the list is based on the query behind the record source of the form? Hi
Yes they are part of the list
you see I have this table which hold the list of name and their email addresses.
The form shows selected email address based on some criteria.
I hope this helps.
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form
Sorry Tara
Still trying to clarify.
Is there an actual ListBox on your form with a RowSource of the names and emails
OR
have you designed a form to return names and emails of specified people based on a query? Quote:
Originally Posted by tara99 Hi
Yes they are part of the list
you see I have this table which hold the list of name and their email addresses.
The form shows selected email address based on some criteria.
I hope this helps. | | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form
Ok
lets go a stet back,
I have a form that have a list box contaning the list of items that are availabe in my database, and a button next to it.
When a user select a item from the list and click on the button it will open a new form with information about that selected item in my case contacts name and email address. (there may be 1 contact per item or could be 100 contacts per item), now I have a button called send email, when I press it I want it to send email to those contacts.
I hope it is clear now, let me know if it is not
Thanks
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form
OK, try this: Put this function in a module: -
-
Function sendEmail(emailAddresses As String, subjectLine As String, message As String)
-
' send the email
-
DoCmd.SendObject acSendNoObject, , , emailAddresses, , , subjectLine, message, False
-
-
End Function
-
-
Go to the Data tab and set the Bound Column to 2 (Assumes 2 columns Name and email in the listbox).
Put a second text box on your form to enter the Subject Line, I'm calling it subjectTxt for this example
I'm calling the message textbox messageTxt.
Note in your listbox in the email column all email addresses have to be separated using semi colons
Then behind the email button put the following code. -
-
sendEMail(lstBoxName, subjectTxt, messageTxt)
-
-
| | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form Quote:
Originally Posted by mmccarthy OK, try this: Put this function in a module: -
-
Function sendEmail(emailAddresses As String, subjectLine As String, message As String)
-
' send the email
-
DoCmd.SendObject acSendNoObject, , , emailAddresses, , , subjectLine, message, False
-
-
End Function
-
-
Go to the Data tab and set the Bound Column to 2 (Assumes 2 columns Name and email in the listbox).
Put a second text box on your form to enter the Subject Line, I'm calling it subjectTxt for this example
I'm calling the message textbox messageTxt.
Note in your listbox in the email column all email addresses have to be separated using semi colons
Then behind the email button put the following code. -
-
sendEMail(lstBoxName, subjectTxt, messageTxt)
-
-
Thank you so much Mccarty
I will try this, and please keep an ey open for this subject I may be back soon
Thanks again heaps
| | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form Quote:
Originally Posted by tara99 Thank you so much Mccarty
I will try this, and please keep an ey open for this subject I may be back soon
Thanks again heaps I tried that code, it gave me error, some thing about sendobject
???
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form Quote:
Originally Posted by tara99 I tried that code, it gave me error, some thing about sendobject
??? I need to know exactly what the error was.
| | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form Quote:
Originally Posted by mmccarthy I need to know exactly what the error was. It says compiler error: Syntax error
I have the following code behind the button
Private Sub Command7_Click()
sendEmail(List8,Text10,Text12)
End Sub
and this one in module
Function sendEmail(EmailAddresses As String, SubjectLine As String, Message As String)
DoCmd.SendObject acSendNoObject, , , EmailAddresses, , , SubjectLine, , , Message, False
End Function
Thanks
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form
You have too many commas between SubjectLine and Message. It should be:
DoCmd.SendObject acSendNoObject, , , EmailAddresses, , , SubjectLine, Message, False
| | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form
Hi
I tried removing those extra commas but still I get the same message, "Compiler error", "Syntax error"
Function sendEmail(EmailAddresses As String, SubjectLine As String, Message As String)
DoCmd.SendObject acSendNoObject, , , EmailAddresses, , , SubjectLine, Message, False
End Function
Thanks
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form
Can you show me the full text of the email addresses you are trying to send. If its too long I just need to see how the addresses are being stored and displayed so just include the first part of the string covering a few addresses.
| | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form Quote:
Originally Posted by mmccarthy Can you show me the full text of the email addresses you are trying to send. If its too long I just need to see how the addresses are being stored and displayed so just include the first part of the string covering a few addresses. At the moment it only has two email addresses, hotmail and yahoo.
In Imediate window I run ?List8 and Text10 and Text12
They are all Null
Cheers
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form Quote:
Originally Posted by tara99 At the moment it only has two email addresses, hotmail and yahoo.
In Imediate window I run ?List8 and Text10 and Text12
They are all Null
Cheers Tara for this to work it needs a series of email addresses
pass through the following
sendEmail("somebody@yahoo.com;somebody@hotmail.com","Test1","MessageText")
just to test it.
| | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form Quote:
Originally Posted by mmccarthy Tara for this to work it needs a series of email addresses
pass through the following
sendEmail("somebody@yahoo.com;somebody@hotmail.com","Test1","MessageText")
just to test it.
I Tried that, still gives me the same error.
Do you think I need to add some library ????
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form Quote:
Originally Posted by tara99 I Tried that, still gives me the same error.
Do you think I need to add some library ???? A syntax error doesn't indicate this and its part of the standard library.
Where are you putting this function?
| | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form Quote:
Originally Posted by mmccarthy A syntax error doesn't indicate this and its part of the standard library.
Where are you putting this function? It is behind the button, (in form)
Private Sub Command7_Click()
sendEmail(List8,Text10,Text12)
'sendEmail("tara_f99@hotmail.com","testsubject","t estmessage")
End Sub
and this one in Module
Function sendEmail(EmailAddresses As String, SubjectLine As String, Message As String)
DoCmd.SendObject acSendNoObject, , , EmailAddresses, , , SubjectLine, Message, False
End Function
Thanks
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form
This should be working fine. Which email are you using outlook, outlook express or other?
| | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form Quote:
Originally Posted by mmccarthy This should be working fine. Which email are you using outlook, outlook express or other? I ma using Novell GroupWise
Tara
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form Quote:
Originally Posted by tara99 I ma using Novell GroupWise
Tara That's your problem. The Access sendObject only works well with outlook and outlook express. I'll see if I can find a routine that works with groupwise.
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form Quote:
Originally Posted by mmccarthy That's your problem. The Access sendObject only works well with outlook and outlook express. I'll see if I can find a routine that works with groupwise. Tara
You will find a class for doing what you want to do here. Download and implement it as best you can and if you need any further help let me know.
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 16,349
| | | re: Sending emai via access form Quote:
Originally Posted by mmccarthy You will find a class for doing what you want to do here. Download and implement it as best you can and if you need any further help let me know. You didn't post any link M :(
| | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form Quote:
Originally Posted by mmccarthy Tara
You will find a class for doing what you want to do here. Download and implement it as best you can and if you need any further help let me know. where is the link
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form Quote:
Originally Posted by tara99 where is the link
Sorry Tara
http://www.mvps.org/access/modules/mdl0059.htm
| | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form Quote:
Originally Posted by mmccarthy Sorry Tara
http://www.mvps.org/access/modules/mdl0059.htm Hi
It doesn't opens this database,
If you are able to open it, would you please copy and paste it here so i can use it
thanks
| | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form Quote:
Originally Posted by tara99 Hi
It doesn't opens this database,
If you are able to open it, would you please copy and paste it here so i can use it
thanks Hi Maccarthy
I have the first program in one module (What did you say to call the module? GW????), and the 2nd program in second module.
Now behind the button I have this code
sendGWEmail "List8", "Text10", "Text12"
I have added the few GroupWise libraries as well.
There is still compilation problem
It first complains about the
sendGWEmail "List8", "Text10", "Text12"
Then when I try to step though it complains about the “Invalid use of Me keyword”
Any idea
I thought it may be because of the module name
What did you say tho call the module?
Thanks
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,115
| | | re: Sending emai via access form Quote:
Originally Posted by tara99
What did you say to call the module? GW????)
, and the 2nd program in second module. This is correct the first module is GW Quote:
Now behind the button I have this code
sendGWEmail "List8", "Text10", "Text12" if you type sendGWEmail followed by a space does it prompt you for entry Quote:
Then when I try to step though it complains about the “Invalid use of Me keyword” Where have you used the Me keyword?
| | Member | | Join Date: Oct 2006
Posts: 106
| | | re: Sending emai via access form Quote:
Originally Posted by mmccarthy This is correct the first module is GW Quote:
if you type sendGWEmail followed by a space does it prompt you for entry
yes it does Quote:
Where have you used the Me keyword?
It is in the first program you send me
thanks
| | Newbie | | Join Date: Oct 2006 Location: England
Posts: 9
| | | re: Sending emai via access form
I'm only a newbie and there may be severe limitations using this method and perhaps it may be appear overly complicated but it works for me at least the 4 people I've tested it on.
I include a column in a member table of email addresses and a column email y/n and link this to the display of details in a personal details main form so that individuals to receive email can be set
I do a query selecting all individuals from the member table attach this to a combo box
I attach this to a E-mail drop down form that has 3 butttons and a very large text box and the query form
1 Button uses a query update to update the main table emaily/n with all yesses
1 Button uses a query update to update the main table emaily/n with all noes (to reset all individuals selected)
1 Button Emails all the individuals currently selected.
I alter the empty text box caption to add all individuals selected using vb to add the individual details to the text box caption separated by a comma dropping the last comma.
I then Email this caption, using the method described in lots of places elsewhere in the community
|  | Member | | Join Date: Oct 2006 Location: Woolongong, Australia
Posts: 76
| | | re: Sending emai via access form
This module uses the Windows MAPI object to open a mail session & send mail to a list of email addresses -
Sub SendMail()
-
-
Dim objSession As MAPI.Session ' Local
-
Dim objMessage As Message ' local
-
Dim objRecip As Recipient
-
On Error GoTo error_olemsg
-
Dim doc As busobj.IDocument
-
Dim rep As busobj.Report
-
Dim DPName As String
-
Dim test As Boolean
-
-
-
-
Set objSession = CreateObject("MAPI.Session")
-
objSession.Logon profileName:="bo_admin", newSession:=False, showDialog:=False
-
-
If objSession Is Nothing Then
-
Err.Raise 10, "MA MACRO", "must first log on; use Session->Logon"
-
Exit Sub
-
End If
-
-
Set objMessage = objSession.Outbox.Messages.Add
-
If objMessage Is Nothing Then
-
Err.Raise 11, "MA MACRO", "could not create a new message in the Outbox"
-
Exit Sub
-
End If
-
-
With objMessage ' message object
-
' Substitue this with your subject
-
.Subject = "Resort -Monthly Report"
-
' Substitue with your the message in body part of the mail
-
.Text = "The Monthly reports for " & Format(Now, "mmm") & " is attached herewith."
-
For i = 1 To ThisDocument.DataProviders.Count
-
If ActiveDocument Is Nothing Then
-
MsgBox "NO Active Document to refresh"
-
Else
-
Set doc = ActiveDocument
-
If Not doc.IsAddIn Then
-
-
'use this for converting to csv
-
-
DPName = "C:\" + DataProviders.Item(i).Name
-
test = DataProviders.Item(i).ConvertTo(boExpAsciiCSV, 1, DPName)
-
-
'use this for converting to pdf format
-
-
-
Else
-
End If
-
End If
-
Set objAttach = .Attachments.Add ' add the attachment
-
-
If objAttach Is Nothing Then
-
Err.Raise 12, "MA MACRO", "Unable to create new Attachmentobject"
-
Exit Sub
-
End If
-
-
-
With objAttach
-
-
-
.Name = DataProviders.Item(i).Name & ".csv"
-
.Source = "C:\" & DataProviders.Item(i).Name & ".csv"
-
-
End With
-
-
-
.Update ' update message to save attachment in MAPI system
-
-
Next i
-
-
Set objRecip = .Recipients.Add
-
With objRecip
-
objRecip.Name = ("MAILID") 'substitue with the mailid of the recipient or groupname
-
objRecip.Type = CdoTo
-
objRecip.Resolve
-
End With
-
-
' use this for sending to a recipient as cc
-
-
'Set objRecip = .Recipients.Add
-
'With objRecip
-
' objRecip.Name = ("ddas")
-
'objRecip.Type = CdoCc
-
'objRecip.Resolve
-
'End With
-
-
-
.Update
-
' update message to save attachment in MAPI system
-
.Send showDialog:=False
-
End With
-
For i = 1 To ThisDocument.DataProviders.Count
-
Kill "C:\" & DataProviders.Item(i).Name & ".csv"
-
Next i
-
objSession.Logoff
-
Exit Sub
-
-
-
error_olemsg:
-
'MsgBox "Error " & Str(Err) & ": " & Error$(Err)
-
Err.Raise 13, "MA MACRO", "Error " & Str(Err) & ": " & Error$(Err)
-
Resume Next
-
-
End Sub
-
|  | Similar Microsoft Access / VBA bytes | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 230,958 network members.
|