Results 1 to 3 of 3
  1. #1
    DR1989 is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    2

    For each recordset create a mail with the query as attachement

    I'm trying to create for each rs a mail item. This mail item should have a temporary query as attachement. Via TransferSpreadSheet I load my temporary Query into Folder.
    This is working. But now, after creating the mail, my attachement is always the same.
    I'm also thinking about a solution which is loading my query results in a excel template, and then send the email with my loaded template as attachement. The template would have a better design, as my "transferspreadsheet" - attachement.

    First question: What am I doing wrong, with my acutal VBA?


    Second question: Is it possible to load the query result for each recordset in a template and send them out?

    Code:
     
    
    1. Sub ExcelExportuSenden()
    2. Dim day As Integer
    3. day = Weekday(Date, vbSunday)
    4. Dim olApp As Outlook.Application
    5. Dim toMulti, waarde As String
    6. Dim mItem As Outlook.MailItem ' An Outlook Mail item
    7. Dim dbs As Database
    8. Dim qdfTemp As QueryDef
    9. Dim qdfNew As QueryDef
    10. Dim originalSql As String
    11. Dim Identified_name As Recordset
    12. Dim qdf As DAO.QueryDef
    13. Set dbs = CurrentDb
    14. Set olApp = CreateObject("Outlook.Application")
    15. Set mItem = olApp.CreateItem(olMailItem)
    16. Dim rs As Recordset
    17. Set rs = CurrentDb.OpenRecordset("Mailrecipient") 'Get name for the email recipient
    18. If rs.RecordCount > 0 Then
    19. rs.MoveFirst
    20. Do Until rs.EOF
    21. With mItem
    22. Set mItem = olApp.CreateItem(olMailItem)
    23. .BodyFormat = olFormatHTML
    24. toMulti = rs![email]
    25. waarde = toMulti
    26. For Each qdf In dbs.QueryDefs
    27. If qdf.Name = "inquiry" Then
    28. dbs.QueryDefs.Delete "inquiry"
    29. Exit For
    30. End If
    31. Next
    32. Set qdfTemp = dbs.CreateQueryDef("inquiry")
    33. With dbs
    34. 'Run query on selected Name product manager
    35. qdfTemp.SQL = "SELECT * FROM [query_each_supplier] WHERE [supplier] = '" & rs![supplier] & "'"
    36. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "inquiry", "Q:\LU\Test\inquiry.xlsx", True
    37. End With
    38. .To = toMulti
    39. MsgBox toMulti
    40. .Subject = "inquiry"
    41. .HTMLBody = ""
    42. .Display
    43. .Attachments.Add ("Q:\LU\Test\Anfrage_zur_Ausschreibung.xlsx")
    44. End With
    45. rs.MoveNext
    46. Loop
    47. Else
    48. MsgBox "No email address!"
    49. End If
    50. olApp.Quit
    51. Set olApp = Nothing
    52. Exit Sub
    53. End Sub
    Many thanks!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    why does the attached file: "Q:\LU\Test\Anfrage_zur_Ausschreibung.xlsx"
    not the same file as the one you exported:"Q:\LU\Test\inquiry.xlsx"
    ?

  3. #3
    DR1989 is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    2
    Sorry, this was a mistake from me, as I translate it in english. Of course it's the same, but it do not work

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

Similar Threads

  1. Replies: 5
    Last Post: 01-16-2016, 10:44 AM
  2. attachement
    By fucell26 in forum Access
    Replies: 3
    Last Post: 07-09-2014, 03:12 AM
  3. Replies: 2
    Last Post: 12-13-2013, 03:13 PM
  4. Replies: 2
    Last Post: 05-05-2013, 12:41 PM
  5. Replies: 11
    Last Post: 09-12-2011, 11:30 AM

Tags for this Thread

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