Page 5 of 7 FirstFirst 1234567 LastLast
Results 61 to 75 of 101
  1. #61
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    OK. Thanks for clarifying. I was still stuck on the Report being broken. You are correct to pay attention to the iteration of the Email addresses. In other words, we are on the next step. What we need now is a list of partners. The current code is doing this here.
    Code:
    Set db = CurrentDb
    Set rs = db.OpenRecordset(strSQL & strWhere, dbOpenSnapshot)
    So we need to not use this dataset that has 70+ records in it. We need to replace strSQL & strWhere with something like ...
    Code:
    SELECT Missions.Code, Missions.[E-mail address]
    FROM Missions
    Do you want to test this for us? You should be able to create a new query and paste that into SQL view. Let me know how many records appear. Meanwhile, I will prepare to post the next step, which will be creating a duplicate Missions table for testing purposes.

  2. #62
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Assuming the SQL in post #61 works you will want to do the following ...

    In order to test dynamic emails, we need to create a dummy table. Your table objects are represented in the Navigation Pane, using an icon and their names. We need to duplicate your Missions table for testing purposes.

    Right click the Missions table and Copy. Then paste by right clicking another or the same table, then paste. It is a simple Copy then Paste. A dialog box will appear. Select Structure and Data and give your new table the name, Missions2.

    Open Missions2 in Datasheet View and delete most of the records. Leave about 4 or 7 records for testing purposes. Now, replace ALL of the email addresses with your personal email address that you have been using for testing. Close the table.

    What is left should be a short list of partners and each partner should have your Email address, not theirs.

  3. #63
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Now you can use the following code to test. It will use your Missions2 table. Any Email address in Missions2 table will receive a report. This will go in the click event of your button.

    Code:
    'Declare variables and assign values
    Dim strReportName As String
    Dim strPath As String
    Dim strFullPath As String
    Dim strEmailAddress As String
    Dim strSubject As String
    Dim strBody As String
    strReportName = "All Payments to Partners"
    strEmailAddress = ""
    strSubject = "This is my report"
    strBody = ""
    'before exporting your report you will want to make
    'sure there is not a file in the folder with the same name
    'and that the folder actually exists
    strPath = manageTempFolder
    strFullPath = strPath & "\" & strReportName & ".pdf"
    'Bail if there is a problem with the directory
    If strPath = "" Then
    Exit Sub
    End If
    'We will use the query object as the recordsource of the Report.
    'and assign dynamic SQL to the QueryDef
    Dim strQueryName As String
    strQueryName = "All Payments to Partners"
    'Use DAO to open a recordset and iterate
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim qryDef As DAO.QueryDef
    Dim strSQL As String
    Dim strWhere As String
    Dim strOrderBy As String
    strSQL = "SELECT [Prefix] & ' ' & [Full Name (Exc Prefix)] AS Partner, " & _
             "[Non-Cheque Payments].[Date], [Non-Cheque Payments].[Amount], [Missions].[E-mail address], " & _
             "[Non-Cheque Payments].Code " & _
             "FROM [Non-Cheque Payments] INNER JOIN [Missions] ON [Non-Cheque Payments].Code = [Missions].Code "
    strWhere = "WHERE ([Non-Cheque Payments].Code NOT IN ('CONEX', 'PAYPA', 'FLOAT', 'WEC')) "
    strOrderBy = "ORDER BY [Prefix] & ' ' & [Full Name (Exc Prefix)], [Non-Cheque Payments].[Date];"
     
    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT DISTINCT Missions2.Code, Missions2.[E-mail address] FROM Missions2", dbOpenSnapshot)
    
    Set qryDef = db.QueryDefs(strQueryName)
    rs.MoveFirst
    'Use early binding to create an email
    Dim objOutlook As New Outlook.Application
    Dim objNewEmail As MailItem
    Dim objAttachReport As Attachments
    While rs.EOF = False
    'WHERE (((Missions.Code)="AIM"))
        strEmailAddress = rs![E-mail address]
        strBody = "Dear " & rs![ReplaceWithFieldName] & ":<br><br>Please find a copy of my report attached here."
        strWhere = strWhere & "AND [Missions].Code = '" & rs![ReplaceWithFieldName] & "' "
        qryDef.SQL = strSQL & strWhere & strOrderBy
        
        'create a report in the temp folder
        DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFullPath
        
        
            'Instantiate your objects
            Set objNewEmail = objOutlook.CreateItem(olMailItem)
            Set objAttachReport = objNewEmail.Attachments
            'Add your file to the Attachments Collection
            objAttachReport.Add strFullPath, olByValue
            
                With objNewEmail
                    .BodyFormat = olFormatRichText
                    .To = strEmailAddress
                    .Subject = strSubject
                    .HTMLBody = strBody
                    'Save the email to ensure the attachment is a
                    'copy of the original file (olByValue)
                    .Save
                    .Send
                End With
            
    ''    'Delete the report you just emailed
        Kill strFullPath
        'Reset the Attachments collection
        'Using the collection is useful when there is more
        'than one attachnebnt per email
        Set objNewEmail = Nothing
        Set objAttachReport = Nothing
        
        
        'Rinse and repeat
        rs.MoveNext
    'Close the loop
    Wend 'rs.EOF now is True
     
    'tidy up
    Set objAttachReport = Nothing
    Set objNewEmail = Nothing
    Set objOutlook = Nothing
    qryDef.SQL = strSQL
    Set qryDef = Nothing
    rs.Close
    Set rs = Nothing
    Set db = Nothing
    MsgBox "Complete"

  4. #64
    Baldeagle is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    I have made a new query as suggested but because the Table called Missions has more records in it than the number of Partners who received money last year I have replaced 'Mission' in your code with 'All Payments to Partners (Single)' and this produces the 32 entries that we need.
    Code:
    SELECT [All Payments to Partners (Single)].Missions.Code, Missions.[E-mail address] AS Expr1FROM [All Payments to Partners (Single)];
    Should I give this new query a name such as 'Select Partners'?

  5. #65
    Baldeagle is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    I have run the new code and it has sent 5 emails but the attachments to numbers 2 to 5 are still not containing the appropriate details - the first Partner's attachment is fine, as before.

  6. #66
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    The problem will be when it comes time to test. We need to replace the Missions table with a temporary testing table. See post #61.
    Try this SQL instead.
    Code:
    SELECT DISTINCT Missions.Code, Missions.[E-mail address] FROM Missions

  7. #67
    Baldeagle is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    Sorry, but I think we are overlapping each other with our comments!

    I created a new Missions2 Table and reduced it to 5 entries which all received payments. I ran your code as set out in Post #63 with the result I described in post #65
    I have run the new code and it has sent 5 emails but the attachments to numbers 2 to 5 are still not containing the appropriate details - the first Partner's attachment is fine, as before.
    Not sure what I'm supposed to do with your post #66?

  8. #68
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Yeah sorry about that. I like to take things one step at a time. However, there will be times I need to step away from my desk. I believe we will be able to refer back to post #63. I will edit that post as needed.
    Not sure what I'm supposed to do with your post #66?
    We need to test the SQL in post #66. I the SQL you provided that is based on the query object will not suffice for testing purposes.

    I hope to use the SQL in post #66, but it should be tested in the Query Designer, first. I am imagining something like the following for testing. I will edit post 63 as needed.
    Code:
    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT DISTINCT Missions2.Code, Missions2.[E-mail address] FROM Missions2", dbOpenSnapshot)

  9. #69
    Baldeagle is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136

    Last stages?

    Good morning. Not sure whether the ball's in my court or not! I think that there are 2 things to resolve before the final linking everything together -
    1. We need to overcome the missing details in all but the first report generated by the latest code.
    2. Can I assume that now that we have established that using the temporary Table 'Missions2' works it would be a question of replacing all references to 'Mission2' with my single query 'All Payments to Partners (Single)'?

    Are you able to resolve the point at 1 at this stage?

  10. #70
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    The code in post #63 has been revised to include the SQL described in post #68. It will depend on Missions2 table. Make sure the Email addresses in your Mission2 table are addresses you can send a test to.

  11. #71
    Baldeagle is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    I have used the revised code from post #63 but while the 4 or 5 test emails are sent with the attached single page report, only the 1st report has the appropriate details included. I deleted the first Partner from Mission2 and it is still the first Partner's report that is correct!

  12. #72
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Build a query using the following and save it.
    Code:
    SELECT DISTINCT Missions2.Code, Missions2.[E-mail address] FROM Missions2
    Then build a second query. Add the previous query described to the design surface. Then, add the other the query, the query described in post #60. Join the two on Code. Save this new query. And take a look at it on DS view. Look at the report, using this new query as the Report's Recordsource.

    There is not an obvious reason why you are experiencing the results you described. If the above exercise does not provide an explanation, the only thing left is for you to upload an example DB here. You will have to create a blank DB an import the relevant tables, queries and report. Remove all sensitive data. Compact and Repair. Then compress (zip) the file and upload it here.

  13. #73
    Baldeagle is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    Having followed your suggestions in the last post I end up with a 5 page report with all the appropriate details in each page - just the same as before!

    I will go ahead and assemble a DB with the relevant tables queries and the report - just one question 'Can you guide me as to how to zip the DB & upload it?'

  14. #74
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by Baldeagle View Post
    ... just one question 'Can you guide me as to how to zip the DB & upload it?'
    You can right click the Access file and choose Send To > Compressed (Zipped) Folder.

    Then, use the 'Go Advanced' option in the forum here. Scroll down a little and choose 'Manage Attachments'. A new window will open. Browse to the Compressed Folder you created. After you select you Browse to and select your DB, 'Upload' the file/folder. Then close the Manage Attachments window.

    If it is impossible to remove sensitive data, in a way I can still test the DB, we may be able to find another solution.

  15. #75
    Baldeagle is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Sep 2011
    Location
    Northern Ireland
    Posts
    136
    When preparing the DB I discovered that there was a reference in the code to table Missions. I had to change this to Missions2. I then went back to my main DB and did the same. The result was that I sent 5 emails and all of the attachments had details!! But they were all the details for the first Partner! The details hadn't been picked up for the subsequent Partners! Does that throw any light on the problem?
    Code:
    strSQL = "SELECT [Prefix] & ' ' & [Full Name (Exc Prefix)] AS Partner, " & _
             "[Non-Cheque Payments].[Date], [Non-Cheque Payments].[Amount], [Missions2].[E-mail address], " & _
             "[Non-Cheque Payments].Code " & _
             "FROM [Non-Cheque Payments] INNER JOIN [Missions2] ON [Non-Cheque Payments].Code = [Missions2].Code "
    My DB is attached.
    Attached Files Attached Files

Page 5 of 7 FirstFirst 1234567 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Send Emails from outlook
    By WhiskyLima in forum Access
    Replies: 8
    Last Post: 08-11-2014, 11:02 AM
  2. Loop Through Query, Send Multiple Emails
    By tdoolittle in forum Reports
    Replies: 6
    Last Post: 05-12-2014, 09:33 PM
  3. Programming Access to Send Emails?
    By BMW150 in forum Access
    Replies: 8
    Last Post: 09-17-2013, 06:14 PM
  4. Send Emails Automatically
    By cbrsix in forum Programming
    Replies: 10
    Last Post: 10-19-2012, 10:52 AM
  5. Replies: 1
    Last Post: 06-26-2012, 09:37 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