Results 1 to 2 of 2
  1. #1
    kman42 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    40

    Change report recordsource without opening?

    I'm trying to send reports via email using VBA, but I can't figure out how to filter the recordsource so that only a single record goes to each person. Here's my code:



    Dim strSQL As String

    On Error Resume Next
    Dim DB As Database
    Dim RSValues As DAO.Recordset
    Set DB = CurrentDb()

    strSQL = "SELECT Email,pk_InitiativeID FROM tbl_Initiatives WHERE NOT EXISTS " & _
    "(SELECT tbl_EventLog.DateOfEvent " & _
    "FROM tbl_EventLog " & _
    "WHERE tbl_EventLog.fk_InitiativeID=tbl_Initiatives.pk_In itiativeID " & _
    "AND tbl_EventLog.fk_EventID=1 )"

    Debug.Print strSQL
    Set RSValues = DB.OpenRecordset(strSQL)
    RSValues.MoveLast
    RSValues.MoveFirst
    Do While Not RSValues.EOF
    Set rpt_Report.RecordSource = "SELECT * FROM tbl_Initiatives WHERE pk_InitiativeID=" & pk_InitiativeID

    DoCmd.SendObject acSendReport, "rpt_Report", acFormatPDF, Email, , , "Status Report for ", "This is a test", 0
    RSValues.MoveNext
    Loop


    It sends the report to the right people so the loop is working fine, but it sends the entire report rather than just the report for the associated person.

    thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,180
    You would have to open the report in design view. You can do something similar in the report's open event, or just set a filter, like this:

    Emailing a different report to each recipient
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Change RecordSource in Tabbed Subforms
    By matchorno in forum Access
    Replies: 4
    Last Post: 03-09-2011, 09:12 AM
  2. Report not opening, just printing.
    By Desstro in forum Reports
    Replies: 3
    Last Post: 12-11-2010, 01:36 PM
  3. Report not opening to view
    By Desstro in forum Programming
    Replies: 4
    Last Post: 11-25-2010, 05:36 PM
  4. Opening a report
    By mwabbe in forum Access
    Replies: 3
    Last Post: 09-17-2010, 09:19 AM
  5. Changing A Report Recordsource from a form
    By warrenjburns in forum Reports
    Replies: 0
    Last Post: 04-09-2009, 05:38 AM

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