Results 1 to 5 of 5
  1. #1
    3 Star Lounger MacroAlan's Avatar
    Join Date
    Feb 2003
    Location
    St Louis, Missouri, USA
    Posts
    254
    Thanks
    6
    Thanked 1 Time in 1 Post
    This code was working yesterday. Do I need to close the Excel file before the attach will work in Access?

    What is the syntax for closing Excel? I am using
    Code:
    	
    	appExcel.Close
    	appExcel.DisplayAlerts = True	'Return control
    	Set appExcel = Nothing
    Code:
    	'4. Create an mailItem and send
    	Set mailObj = Outlook.Application.CreateItem(olMailItem)
    	Let mailObj.Subject = commObj.msgSubject & "(investID=" & investID & ")"
    	Let mailObj.Body = commObj.msgBody
    	Call mailObj.Recipients.Add(commObj.managerEmail)
    
    	' chg docFormName to use naming convention   fName
     '   Call mailObj.Attachments.Add(commObj.workingFolder & "\" & commObj.docFormName, Outlook.olByValue, 1, commObj.docFormName)
    
    	Call mailObj.Attachments.Add(commObj.workingFolder & "\" & fName, Outlook.olByValue, 1, fName)
    	Call mailObj.Send	   'Errors on SEND
    Thanks all!
    Alan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The instruction for closing an instance of Excel named appExcel is

    appExcel.Quit

    What was the error message you got when trying to send the e-mail?

  3. #3
    3 Star Lounger MacroAlan's Avatar
    Join Date
    Feb 2003
    Location
    St Louis, Missouri, USA
    Posts
    254
    Thanks
    6
    Thanked 1 Time in 1 Post
    Outlook does not recognize one or more names
    Alan

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Try this:

    Code:
    Dim objRecipient As Outlook.Recipient
    Set objRecipient = mailObj.Recipients.Add(commObj.managerEmail)
    ' Other code goes here
    ...
    ...
    If Not objRecipient.Resolve Then
      mailObj.Display
    Else
      mailObj.Send
    End If
    If Outlook cannot resolve the recipient name, it'll display the mail message instead of sending it automatically, so that the user can correct the error.
    Of course, you can also decide to discard the mail message.

  5. #5
    3 Star Lounger MacroAlan's Avatar
    Join Date
    Feb 2003
    Location
    St Louis, Missouri, USA
    Posts
    254
    Thanks
    6
    Thanked 1 Time in 1 Post
    That solved it. When the email popped up, my manager's email address was spelled wrong (she typed it).
    Alan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •