473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

E-mail with Access

DJRhino1175
221 128KB
I copied and pasted code I currently use with no issue, but I'm having an issue now. I have the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnGroupEmail_Click()
  2.  
  3. On Error GoTo EH
  4.  
  5.     Dim strSendTo     As String
  6.     Dim strSubject    As String
  7.     Dim strEMailBody  As String
  8.     Dim strCCLine     As String
  9.     Dim strBCCLine    As String
  10.     Dim strOnBehalfOf As String
  11.     Dim MyDB          As DAO.Database
  12.     Dim rstEMail      As DAO.Recordset
  13.     Dim strEMail      As String
  14.  
  15.     DoCmd.SetWarnings False
  16.     DoCmd.OpenQuery "qryEmail", acViewNormal
  17.     DoCmd.SetWarnings True
  18.  
  19. Set MyDB = CurrentDb
  20.  
  21. Set rstEMail = MyDB.OpenRecordset("Select * From tblEMail", _
  22.     dbOpenSnapshot, dbOpenForwardOnly)
  23.  
  24.    With rstEMail
  25.             If Not (.BOF And .EOF) Then
  26.                 Call .MoveFirst
  27.                 Do While Not .EOF
  28.                     'Build the Recipients String
  29.                     strSendTo = ""
  30.                     strSendTo = _
  31.                         strSendTo & _
  32.                         IIf(strSendTo = "", _
  33.                             "", _
  34.                             ";") & !Email
  35.                   Call .MoveNext
  36.                 Loop
  37.             End If
  38.             Call .Close
  39.         End With
  40.  
  41.         Call MyDB.Close
  42.         Set rstEMail = Nothing
  43.         Set MyDB = Nothing
  44.  
  45.     'Generate and Display the E-Mail
  46.  
  47.         Call SendAnEmail(olSendTo:=strSendTo, _
  48.                      olSubject:=strSubject, _
  49.                      olEMailBody:=strEMailBody, _
  50.                      olDisplay:=True, _
  51.                      SendAsHTML:=True)
  52.  
  53.     Exit Sub
  54. EH:
  55.     MsgBox "There was an error sending mail!" & vbCrLf & vbCrLf & _
  56.         "Error: " & Err.Number & vbCrLf & _
  57.         "Description: " & Err.Description & vbCrLf & vbCrLf & _
  58.         "Please contact your Database Administrator.", vbCritical, "WARNING!"
  59.     Exit Sub
  60.  
  61. End Sub
My issue is its not building the sting correctly in the loop. Currently I only have 2 email address' in my table, but it is only putting in one email address. I'm not getting any errors, so I feel like I'm missing something in the loop.

Can anyone see something I'm missing?
Feb 18 '20 #1

✓ answered by twinnyfo

You are setting strSendTo to "" every new email address. Lines 27-36 should be:

Expand|Select|Wrap|Line Numbers
  1.                 strSendTo = ""
  2.                 Do While Not .EOF
  3.                     'Build the Recipients String
  4.                     strSendTo = _
  5.                         strSendTo & _
  6.                         IIf(strSendTo = "", _
  7.                             "", _
  8.                             ";") & !Email
  9.                   Call .MoveNext
  10.                 Loop
Hope this hepps!

3 1833
twinnyfo
3,653 Expert Mod 2GB
You are setting strSendTo to "" every new email address. Lines 27-36 should be:

Expand|Select|Wrap|Line Numbers
  1.                 strSendTo = ""
  2.                 Do While Not .EOF
  3.                     'Build the Recipients String
  4.                     strSendTo = _
  5.                         strSendTo & _
  6.                         IIf(strSendTo = "", _
  7.                             "", _
  8.                             ";") & !Email
  9.                   Call .MoveNext
  10.                 Loop
Hope this hepps!
Feb 18 '20 #2
DJRhino1175
221 128KB
Good fined Twinny, I don't think I would have ever caught that.

Thanks a million
Feb 18 '20 #3
twinnyfo
3,653 Expert Mod 2GB
Glad I could be of service.

Let us know if we can hepp in any other way!
Feb 18 '20 #4

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

Similar topics

1
by: Rene Aguirre | last post by:
Hello, I'd like to make a sort of web tracking system for internal stuff at my office. But I'm having problems about how to add email notification to my script. I already tried to send email...
2
by: Lin Ma | last post by:
Good morning everyone, After someone changed the web server permission, I do not know what he did. I get an error message when I try to use CDO send email. The error message is: CDO.Message.1...
7
by: Daven Thrice | last post by:
I know how to send email out of Access, and that's no problem. What I need to figure out is how to receive email into access. Say that I give access an email address, such as access@daven.com. I...
16
by: cyranoVR | last post by:
This is the approach I used to automate printing of Microsoft Access reports to PDF format i.e. unattended and without annoying "Save As..." dialogs, and - more importantly - without having to use...
14
by: Kevin G. Anderson | last post by:
What: CAUG Meeting - QuickBooks IIF Files; Total Access Analyzer; CAUG Social When: Thursday, May 25, 2006, 6PM Who: Chris Monaghan and Kevin Anderson Where: The Information Management Group...
1
by: Mose | last post by:
Greetings! I am using Access '97 to track company orders. It's a pretty basic setup featuring a main table (tbl_SalesSlip) and a related table (tbl_ModelsSold). I would like to send an email that...
1
by: A49553 | last post by:
I am trying to e-mail reports from Access that are based on pass-through queries going to an Oracle database. I am using Access 2003 on a Windows XP OS. I was able to e-mail these on my previous PC...
10
by: Dan2kx | last post by:
Hello to all, i have a new interesting problem to solve.... i have a report that i would like to email to a list of users, the report is a full page document and is personalised to each user...
5
by: bloukopkoggelmander | last post by:
Hi all Right, unless I am going completely bonkers, I am sure there is a law in place that stops companies from accessing their user's email unless they have written permission from the employee...
1
by: LosingitLen | last post by:
Access to outlook (.com) and (manual check of) Windows Update FAILS! Been this way for about 5 out of the last 8 months. Ahhh! I think it may be a security issue, possibly a CERTIFICATE thingy...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.