Send an Email BCC only

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DJRhino1175
    New Member
    • Aug 2017
    • 221

    Send an Email BCC only

    I use this public function:

    Code:
    Public Function SendAnEmail(olSendTo As String, _
                                olSubject As String, _
                                olEMailBody As String, _
                                olDisplay As Boolean, _
                       Optional olCCLine As String, _
                       Optional olBCCLine As String, _
                       Optional olOnBehalfOf As String, _
                       Optional olAtchs As String, _
                       Optional SendAsHTML As Boolean) As Boolean
    On Error GoTo EH
        Dim olApp       As Outlook.Application
        Dim olMail      As Outlook.MailItem
        Dim strArray()  As String
        Dim intAtch     As Integer
    
        Set olApp = CreateObject("Outlook.Application")
        Set olMail = olApp.CreateItem(olMailItem)
        With olMail
            .To = olSendTo
            .subject = olSubject
     
            If SendAsHTML Then
                .BodyFormat = olFormatHTML
                .HTMLBody = olEMailBody
            Else
                .body = olEMailBody
            End If
     
            .CC = olCCLine
            .BCC = olBCCLine
            .SentOnBehalfOfName = olOnBehalfOf
            strArray = Split(olAtchs, "%Atch")
     
            For intAtch = 0 To UBound(strArray)
                If FileExists(strArray(intAtch)) Then _
                    .Attachments.Add strArray(intAtch)
            Next intAtch
     
            If olDisplay Then
                .Display
            Else
                .Send
            End If
     
        End With
        Set olMail = Nothing
        Set olApp = Nothing
     
        SendAnEmail = True
     
        Exit Function
    EH:
        MsgBox "There was an error generating the E-Mail!" & vbCrLf & vbCrLf & _
            "Error: " & Err.Number & vbCrLf & _
            "Description: " & Err.Description & vbCrLf & vbCrLf & _
            "Please contact your Database Administrator.", vbCritical, "WARNING!"
        SendAnEmail = False
        Exit Function
    End Function
    Which is called out in this sub routine:

    Code:
    Private Sub btnGroupEmail_Click()
     
    On Error GoTo EH
     
        Dim strSendTo     As String
        Dim strSubject    As String
        Dim strEMailBody  As String
        Dim strCCLine     As String
        Dim strBCCLine    As String
        Dim strOnBehalfOf As String
        Dim MyDB          As DAO.Database
        Dim rstEMail      As DAO.Recordset
        Dim strEMail      As String
     
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "qryEmail", acViewNormal
        DoCmd.SetWarnings True
     
    Set MyDB = CurrentDb
     
    Set rstEMail = MyDB.OpenRecordset("Select * From tblEMail", _
        dbOpenSnapshot, dbOpenForwardOnly)
     
       With rstEMail
                If Not (.BOF And .EOF) Then
                    Call .MoveFirst
                    Do While Not .EOF
                        'Build the Recipients String
                        strSendTo = _
                            strSendTo & _
                            IIf(strSendTo = "", _
                                "", _
                                ";") & !Email
                      Call .MoveNext
                    Loop
                End If
                Call .Close
            End With
     
            Call MyDB.Close
            Set rstEMail = Nothing
            Set MyDB = Nothing
     
        'Generate and Display the E-Mail
     
            Call SendAnEmail(olSendTo:=strSendTo, _
                         olSubject:=strSubject, _
                         olEMailBody:=strEMailBody, _
                         olDisplay:=True, _
                         SendAsHTML:=True)
     
        Exit Sub
    EH:
        MsgBox "There was an error sending mail!" & vbCrLf & vbCrLf & _
            "Error: " & Err.Number & vbCrLf & _
            "Description: " & Err.Description & vbCrLf & vbCrLf & _
            "Please contact your Database Administrator.", vbCritical, "WARNING!"
        Exit Sub
     
    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.
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    DJ,

    Easy:

    Code:
            Call SendAnEmail(olBCCLine:=strSendTo, _
                         olSubject:=strSubject, _
                         olEMailBody:=strEMailBody, _
                         olDisplay:=True, _
                         SendAsHTML:=True)
    You are confusing your variables with your arguments.

    Hope this hepps!

    Comment

    • DJRhino1175
      New Member
      • Aug 2017
      • 221

      #3
      So I changed that, but now it doesn't compile. It tells me

      "Argument not optional" in this section:

      Code:
       Call SendAnEmail(olBCCLine:=strSendTo, _
                           olSubject:=strSubject, _
                           olEMailBody:=strEMailBody, _
                           olDisplay:=True, _
                           SendAsHTML:=True)

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3653

        #4
        Code:
        Call SendAnEmail(olSendTo:="", _
                         olSubject:=strSubject, _
                         olEMailBody:=strEMailBody, _
                         olBCCLine:=strSendTo, _
                         olDisplay:=True, _
                         SendAsHTML:=True)
        You should be better able to troubleshoot these by now, DJ....

        Comment

        • DJRhino1175
          New Member
          • Aug 2017
          • 221

          #5
          Thanks Twinny,

          Still finding some of this stuff confusing.

          Comment

          • twinnyfo
            Recognized Expert Moderator Specialist
            • Nov 2011
            • 3653

            #6
            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!

            Comment

            Working...