Results 1 to 7 of 7
  1. #1
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    Email attachment that is listed in text field

    Hello! I need to send an eBlast to many customers with an attachment (the same attachment for everyone). First the user will find the file they want to attach, and that file name is stored in a field on my form called "Attachment". There's a message body and subject field as well for customization. When I go to attach the file, I get an error, because there aren't quotes around the file name, I've attempted to add quotes and get nowhere obviously. It works fine if I spell out the filepath, but I don't want to do that, I want to choose the file. The error message is "object doesn't support this property or method", here's the code:


    Code:
    Private Sub Command13_Click()  'Sub SendMessages(Optional AttachmentPath)
     
      Dim MyDB As dao.Database
      Dim MyRS As dao.Recordset
      Dim objOutlook As Outlook.Application
      Dim objOutlookMsg As Outlook.MailItem
      Dim objOutlookRecip As Outlook.Recipient
      Dim objOutlookAttach As Outlook.attachment
      Dim TheAddress As String
    
    
     
      Set MyDB = CurrentDb
      Set MyRS = MyDB.OpenRecordset("customeremails")
      MyRS.MoveFirst
     
      ' Create the Outlook session.
      Set objOutlook = CreateObject("Outlook.Application")
     
      Do Until MyRS.EOF
      ' Create the e-mail message.
      Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
      TheAddress = MyRS![Email]
     
         With objOutlookMsg
            ' Add the To recipients to the e-mail message.
            Set objOutlookRecip = .Recipients.Add(TheAddress)
            objOutlookRecip.Type = olTo
     
     
            ' Set the Subject, the Body, and the Importance of the e-mail message.
            .Subject = Me.Subject
            .Body = Me.message
            
            'Add the attachment to the e-mail message.
            If Not IsMissing(Me.attachment) Then
              .Attachments.Add(Me.attachment)
            End If
     
            ' Resolve the name of each Recipient.
            For Each objOutlookRecip In .Recipients
               objOutlookRecip.Resolve
               If Not objOutlookRecip.Resolve Then
                 objOutlookMsg.Display
               End If
            Next
            .Send
          End With
          MyRS.MoveNext
       Loop
       Set objOutlookMsg = Nothing
       Set objOutlook = Nothing
    End Sub
    Any thoughts for how I can refer to the text field on my form? Thanks in advance you guys! Happy weekend!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    I send stuff without quote all the time.
    you MUST have the full filepath,otherwise its not a file.

    I hope your me.attachment is NOT an access attachment, but rather a textbox named attachment and in it is the full filepath.

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    If Me.Attachment is a textbox holding the full path to the file including the extension (C:\MyDbFolder.CustomerSurvey.pdf) then this code should look like this:
    Code:
     'Add the attachment to the e-mail message.
            If Not IsNull(Me.attachment) Then
              .Attachments.Add(Me.attachment)
            End If
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    It is a textbox and the full filepath. Thanks ranman!

  5. #5
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    I pasted this and it's now working! Thank you Gicu!

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    You're very welcome Gina!
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,799
    Maybe research IsMissing function so you know where it can be used? AFAIK, it doesn't apply in that code.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-06-2017, 04:40 PM
  2. Replies: 3
    Last Post: 02-23-2015, 02:13 PM
  3. Replies: 5
    Last Post: 09-05-2014, 12:06 PM
  4. Replies: 13
    Last Post: 12-05-2013, 06:04 PM
  5. Replies: 31
    Last Post: 08-15-2012, 03:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums