By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,326 Members | 1,938 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,326 IT Pros & Developers. It's quick & easy.

sending e-mail using VBA from a button on an Access Form

P: 1
Hi,

I need to know how I can send all of the e-mail address's from clicking on a button that I put on a form in Access to a default e-mail on a computer. This is what I want to be able to do I create a form that has a button on it and when it is click it pulls all of the e-mail address's from my query and puts them into the default e-mail I have on my computer. So that I can e-mail all of the people with out having to type each e-mail address in from my query results. I am using Access 2003 Any help anyone can give would be greatly appreciate thanks in advance for your help.

~Dana
Oct 16 '06 #1
Share this Question
Share on Google+
2 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
Try something like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private sub CommandBtn_Click()
  3.  
  4.     sendEmail("Subject text", "Message text")
  5.  
  6. End Sub
  7.  
  8.  
Put the following function in a module

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function sendEmail(subText As String, message As String)
  3. ' function to send an email 
  4. Dim db As Database
  5. Dim rs As Recordset
  6. Dim mailList As String
  7.  
  8.     Set db = CurrentDb
  9.     Set rs = db.OpenRecordset("SELECT email FROM TableName")
  10.  
  11.     mailList = ""
  12.     rs.MoveFirst
  13.     Do Until rs.EOF
  14.         mailList = mailList & rs!email & ";"
  15.         rs.MoveNext
  16.     Loop
  17.  
  18.     ' send the email
  19.     DoCmd.SendObject acSendNoObject, , , mailList, , , subText, message, False
  20.  
  21.     rs.Close
  22.     Set rs = Nothing
  23.     Set db = Nothing
  24.  
  25. End Function
  26.  
  27.  
Hi,

I need to know how I can send all of the e-mail address's from clicking on a button that I put on a form in Access to a default e-mail on a computer. This is what I want to be able to do I create a form that has a button on it and when it is click it pulls all of the e-mail address's from my query and puts them into the default e-mail I have on my computer. So that I can e-mail all of the people with out having to type each e-mail address in from my query results. I am using Access 2003 Any help anyone can give would be greatly appreciate thanks in advance for your help.

~Dana
Oct 16 '06 #2

P: 1
This is the first time i 've tried to use Access and I am not familiar with VB.
I am trying to perform a similar functiona as Donna wanted to do. I wanted to send e-mail automatically to a group of receipts when I open a form.

1. I have put the sendEmail function in a new model and named it testemailmodel.
2. I have created a table to hold all the e-mail address
3. Could you please guide me through how I can put the sendEmail("Subject text", "Message text") code correct so that when I open a form, it automatically send the e-mails.

Also, I found that I can build a macro by select sendopen object and select the query to send the query result to the receipt. my question is:
1. how can I bypass the confirmation message before the marcro send the e-mail?
2. Is there a way to attach 2 query results in one e-mail?

Thank you very much for your help!
Feb 15 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.