Compile Error: Argument not optional when trying to create an email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anoble1
    New Member
    • Jul 2008
    • 246

    #1

    Compile Error: Argument not optional when trying to create an email

    I have some code that jumps here below and just stops at "GeneralEma il" and gives that Argument not Optional Error.
    Code:
    GenerateEmail "anoble@******.com", ContractorName.Value & " Crew Authorization " & cmbContractID.Column(1, cmbContractID.ListIndex) & "-" & AuthNum.Value & " - Starting " & Forms!frmCrewAuthorization!AuthDate.Value, Forms!frmCrewAuthorization!Name.Value & "'s Crew" & vbCrLf & vbCrLf, outFileName, False
    Then I have a module. Wonder if this works with my Office 2013? But I have Access 2007.
    Code:
    Public Function GenerateEmail(mailTo As String, mailCc As String, mailBcc As String, subject As String, body As String, attachment() As String, autoSend As Boolean)
    
        Set MyOutlook = New Outlook.Application
        Set MyMail = MyOutlook.CreateItem(olMailItem)
        
        i = 0
        While i <= UBound(attachment)
            MyMail.Attachments.Add attachment(i)
            i = i + 1
        Wend
        
        MyMail.To = mailTo
        MyMail.CC = mailCc
        MyMail.BCC = mailBcc
        
        MyMail.subject = subject
        MyMail.body = body
        
        If autoSend Then
            MyMail.Send
        Else
            MyMail.Display
        End If
        
        
        
        Set MyMail = Nothing
        Set MyOutlook = Nothing
        
    End Function
    Last edited by anoble1; Feb 13 '15, 05:29 PM. Reason: Add more info
  • jforbes
    Recognized Expert Top Contributor
    • Aug 2014
    • 1107

    #2
    First thing I see is that you are attempting to pass:
    Code:
    ContractorName.Value & " Crew Authorization " & cmbContractID.Column(1, cmbContractID.ListIndex) & "-" & AuthNum.Value & " - Starting " & Forms!frmCrewAuthorization!AuthDate.Value
    into the "mailCc As String" parameter. I doubt that is right.

    Comment

    Working...