473,387 Members | 1,365 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,387 software developers and data experts.

Send an Email BCC only

DJRhino1175
221 128KB
I use this public function:

Expand|Select|Wrap|Line Numbers
  1. Public Function SendAnEmail(olSendTo As String, _
  2.                             olSubject As String, _
  3.                             olEMailBody As String, _
  4.                             olDisplay As Boolean, _
  5.                    Optional olCCLine As String, _
  6.                    Optional olBCCLine As String, _
  7.                    Optional olOnBehalfOf As String, _
  8.                    Optional olAtchs As String, _
  9.                    Optional SendAsHTML As Boolean) As Boolean
  10. On Error GoTo EH
  11.     Dim olApp       As Outlook.Application
  12.     Dim olMail      As Outlook.MailItem
  13.     Dim strArray()  As String
  14.     Dim intAtch     As Integer
  15.  
  16.     Set olApp = CreateObject("Outlook.Application")
  17.     Set olMail = olApp.CreateItem(olMailItem)
  18.     With olMail
  19.         .To = olSendTo
  20.         .subject = olSubject
  21.  
  22.         If SendAsHTML Then
  23.             .BodyFormat = olFormatHTML
  24.             .HTMLBody = olEMailBody
  25.         Else
  26.             .body = olEMailBody
  27.         End If
  28.  
  29.         .CC = olCCLine
  30.         .BCC = olBCCLine
  31.         .SentOnBehalfOfName = olOnBehalfOf
  32.         strArray = Split(olAtchs, "%Atch")
  33.  
  34.         For intAtch = 0 To UBound(strArray)
  35.             If FileExists(strArray(intAtch)) Then _
  36.                 .Attachments.Add strArray(intAtch)
  37.         Next intAtch
  38.  
  39.         If olDisplay Then
  40.             .Display
  41.         Else
  42.             .Send
  43.         End If
  44.  
  45.     End With
  46.     Set olMail = Nothing
  47.     Set olApp = Nothing
  48.  
  49.     SendAnEmail = True
  50.  
  51.     Exit Function
  52. EH:
  53.     MsgBox "There was an error generating the E-Mail!" & vbCrLf & vbCrLf & _
  54.         "Error: " & Err.Number & vbCrLf & _
  55.         "Description: " & Err.Description & vbCrLf & vbCrLf & _
  56.         "Please contact your Database Administrator.", vbCritical, "WARNING!"
  57.     SendAnEmail = False
  58.     Exit Function
  59. End Function
Which is called out in this sub routine:

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.                         IIf(strSendTo = "", _
  32.                             "", _
  33.                             ";") & !Email
  34.                   Call .MoveNext
  35.                 Loop
  36.             End If
  37.             Call .Close
  38.         End With
  39.  
  40.         Call MyDB.Close
  41.         Set rstEMail = Nothing
  42.         Set MyDB = Nothing
  43.  
  44.     'Generate and Display the E-Mail
  45.  
  46.         Call SendAnEmail(olSendTo:=strSendTo, _
  47.                      olSubject:=strSubject, _
  48.                      olEMailBody:=strEMailBody, _
  49.                      olDisplay:=True, _
  50.                      SendAsHTML:=True)
  51.  
  52.     Exit Sub
  53. EH:
  54.     MsgBox "There was an error sending mail!" & vbCrLf & vbCrLf & _
  55.         "Error: " & Err.Number & vbCrLf & _
  56.         "Description: " & Err.Description & vbCrLf & vbCrLf & _
  57.         "Please contact your Database Administrator.", vbCritical, "WARNING!"
  58.     Exit Sub
  59.  
  60. End Sub
My question is "How Would I send this as BCC: only"?

Tried changing the strSendto string to strBCCLine string in all instances and all that happens is a blank email.
Feb 21 '20 #1

✓ answered by twinnyfo

Expand|Select|Wrap|Line Numbers
  1. Call SendAnEmail(olSendTo:="", _
  2.                  olSubject:=strSubject, _
  3.                  olEMailBody:=strEMailBody, _
  4.                  olBCCLine:=strSendTo, _
  5.                  olDisplay:=True, _
  6.                  SendAsHTML:=True)
You should be better able to troubleshoot these by now, DJ....

5 2168
twinnyfo
3,653 Expert Mod 2GB
DJ,

Easy:

Expand|Select|Wrap|Line Numbers
  1.         Call SendAnEmail(olBCCLine:=strSendTo, _
  2.                      olSubject:=strSubject, _
  3.                      olEMailBody:=strEMailBody, _
  4.                      olDisplay:=True, _
  5.                      SendAsHTML:=True)
You are confusing your variables with your arguments.

Hope this hepps!
Feb 24 '20 #2
DJRhino1175
221 128KB
So I changed that, but now it doesn't compile. It tells me

"Argument not optional" in this section:

Expand|Select|Wrap|Line Numbers
  1.  Call SendAnEmail(olBCCLine:=strSendTo, _
  2.                      olSubject:=strSubject, _
  3.                      olEMailBody:=strEMailBody, _
  4.                      olDisplay:=True, _
  5.                      SendAsHTML:=True)
Feb 24 '20 #3
twinnyfo
3,653 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. Call SendAnEmail(olSendTo:="", _
  2.                  olSubject:=strSubject, _
  3.                  olEMailBody:=strEMailBody, _
  4.                  olBCCLine:=strSendTo, _
  5.                  olDisplay:=True, _
  6.                  SendAsHTML:=True)
You should be better able to troubleshoot these by now, DJ....
Feb 24 '20 #4
DJRhino1175
221 128KB
Thanks Twinny,

Still finding some of this stuff confusing.
Feb 24 '20 #5
twinnyfo
3,653 Expert Mod 2GB
No worries, DJ!

Keep pluggin' away. Soon things will start to become natural. It takes many years to become comfortable with this stuff. You'll get there! Just stay encouraged and keep asking questions!
Feb 24 '20 #6

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

Similar topics

8
by: Samia | last post by:
I have an application running on a single workstation (win 2000) with Outlook installed and a profile create using and exchange server with authentification through the DNS. This user profile is...
1
by: mhawkins19 | last post by:
I have a form built and on the onclick event I validate all of the fields and then if the form is ok, on the submit event I run a javascript function to set a cookie and download a file from the...
1
by: Jay McGrath | last post by:
Help - trying to send a simple text email with with as little user intervention. I am trying to create a button in my Access application that will automatically send a simple text email. It...
9
by: Bob Jones | last post by:
We have developed a commercial ASP.net application (personal nutrition management and tracking); we want to send smtp email from within it. For our development box, we use WinXP Pro, IIS 5.5,...
3
by: =?Utf-8?B?SHVnaA==?= | last post by:
Hi There, I use follow code to send email inside VB.NET 2005. It does not work well. Error message of "Failure sending email" would occue. However, email was sent out sometimes. I am confused...
7
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi guys! I'm looking for a way to send an email from the server to the user (like a newsletter). How can I do this? Does anyone know of a sample code link or something like that? Do I...
16
by: =?Utf-8?B?Q2hlZg==?= | last post by:
I can use outlook2003 to send email,but I cann't use this code below to send email. Please help me to test this code and instruct me how to solve this problem in detail. software...
4
by: shailendra deshpande | last post by:
right now i have only pain html page.and i want to send email through it using javascript plz. anybody tell me how to send email from plain html page using javascript. thanks in advance ...
14
by: Warren Tang | last post by:
Hi I am using the mail function to send a mail like this: $b = mail("my_real_email_address@gmail.com", "Hello from PHP", "Hi, finally sent an email successfully"); But it failed. Could you...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.