Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    wnicole is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    118

    send multiple email...code having problem.

    I was wondering if someone can help me with the code below.
    Table: T_Inspectors (this is where the email addresses are stored [Email])
    Query: Q_WeeklyDispatch_Today (This is the parameter Date()
    Report: R_WeeklyDispatch_Today. (Goal: This report sends to each employee with the jobs attached by email).

    It does everything it needs to do up to the Emailing part. It is not connect the email address to the right report. It appears to be emails the report to the first person on the Table but not connecting at all to the query.


    Can you take a look at the code below and let me know if I'm missing something?
    Thank you
    *********************************************

    Private Sub Command5_Click()

    Dim strCriteria As String
    Dim strDate As String
    Dim strEmail As String

    strCriteria = "[Date]=" & strDate

    DoCmd.OpenReport "R_WeeklyDispatch_Today", acViewPreview, , , acHidden
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("T_Inspectors", dbOpenDynaset) 'We need an email address
    rs.MoveFirst

    Do While Not rs.EOF 'Loop through every record in T_Inspectors and retreive emails

    DoCmd.OpenReport "R_WeeklyDispatch_Today", acViewPreview, , "[Employee]='" & rs![Last Name] & "'"

    DoCmd.SendObject acSendReport, "R_WeeklyDispatch_Today", acFormatPDF, strEmail, , , "Current Jobs", "Please contact Tracy with any concerns 415-525-0000", True

    rs.MoveNext

    Loop

    rs.Close

    Set rs = Nothing
    DoCmd.Close acReport, "R_WeeklyDispatch_Today"





    End Sub

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862

  3. #3
    wnicole is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    118
    I'm trying to see if another programmer can help me with this last leg...Almost there but still not solved.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    You need to close the report inside the loop.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    wnicole is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    118
    See pic...Do you mean like this? When I change for some reason this code is just not pulling up any email. The email part in Outlook is blank. Nothing when I hover over email. It just says StrEmail=
    As if no Email addresses in T_Inspectors is actually connected to the report.
    Click image for larger version. 

Name:	Picture1.png 
Views:	20 
Size:	65.8 KB 
ID:	14057

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    No, above the MoveNext.

    You never set strEmail, so no surprise it's empty.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    wnicole is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    118
    Hi Pbaldy,

    You mentioned that I never "set" strEmail. What do you mean by that? Can you assist me with setting it?
    I'm getting all the correct people on the reports its just not connecting individually to their emails.
    See Code:

    Private Sub Command5_Click()

    Dim strCriteria As String
    Dim strDate As String
    Dim strEmail As String

    strCriteria = "[Date]=" & strDate

    DoCmd.OpenReport "R_InspectorDailyDispatch", acViewPreview, , , acHidden
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("T_Inspectors", dbOpenDynaset) 'We need an email address
    rs.MoveFirst

    Do While Not rs.EOF 'Loop through every record in T_Inspectors and retreive emails

    DoCmd.OpenReport "R_InspectorDailyDispatch", acViewPreview, , "LastName='" & rs![Last Name] & "'"

    DoCmd.SendObject acSendReport, "R_InspectorDailyDispatch", acFormatPDF, strEmail, , , "Current Jobs", "Please contact Tracy with any concerns 415-525-0000", True
    DoCmd.Close acReport, "R_InspectorDailyDispatch"
    rs.MoveNext

    Loop

    rs.Close

    Set rs = Nothing






    End Sub

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    You never give that variable a value, like you do strCriteria.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    wnicole is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    118
    Actually I was given this code. So I'm not skilled as much in writing. Still learning.

    Is this correct?

    strEmail = "[Email]="

  10. #10
    wnicole is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    118
    Excuse me Its Me...
    I was just informed that the strEmail was never set.
    Can you look at the code you sent again, and let me know where I would set the strEmail?

    Private Sub Command5_Click()

    Dim strCriteria As String
    Dim strDate As String
    Dim strEmail As String

    strCriteria = "[Date]=" & strDate

    DoCmd.OpenReport "R_WeeklyDispatch_Today", acViewPreview, , , acHidden
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("T_Inspectors", dbOpenDynaset) 'We need an email address
    rs.MoveFirst

    Do While Not rs.EOF 'Loop through every record in T_Inspectors and retreive emails

    DoCmd.OpenReport "R_WeeklyDispatch_Today", acViewPreview, , "[Employee]='" & rs![Last Name] & "'"

    DoCmd.SendObject acSendReport, "R_WeeklyDispatch_Today", acFormatPDF, strEmail, , , "Current Jobs", "Please contact Tracy with any concerns 415-525-0000", True

    rs.MoveNext

    Loop

    rs.Close

    Set rs = Nothing
    DoCmd.Close acReport, "R_WeeklyDispatch_Today"

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Quote Originally Posted by wnicole View Post
    Actually I was given this code. So I'm not skilled as much in writing. Still learning.

    Is this correct?

    strEmail = "[Email]="
    Would you say that will result in a valid email address being passed to the email code?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    wnicole is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    118
    I have also seen this one used in code.
    strEmail = !Email

    However, I don't know which one I will use as this is my first time really working with email sending. Still trying to get this one complete.

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Where do you expect the address to come from? If the recordset, might this give a hint?

    rs![Last Name]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    wnicole is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    118
    Yes. I tried this. However, its still not connecting the query with the Table when the report is ran. I'm getting all emails in the table not the connecting ones.

    rivate Sub Command5_Click()

    Dim strCriteria As String
    Dim strDate As String
    Dim strEmail As String

    strCriteria = "[Date]=" & strDate



    DoCmd.OpenReport "R_InspectorDailyDispatch", acViewPreview, , , acHidden

    Set rs = CurrentDb.OpenRecordset("Select [Last Name], Email From T_Inspectors", dbOpenDynaset) 'We need an email address
    rs.MoveFirst

    Do While Not rs.EOF 'Loop through every record in T_Inspectors and retreive emails

    DoCmd.OpenReport "R_InspectorDailyDispatch", acViewPreview, , "[Last Name]='" & rs![Last Name] & "'"

    DoCmd.SendObject acSendReport, "R_InspectorDailyDispatch", acFormatPDF, rs!Email, , , "Current Jobs", "Please contact Tracy with any concerns 415-525-0000", True
    DoCmd.Close acReport, "R_InspectorDailyDispatch"
    rs.MoveNext

    Loop

    rs.Close

    Set rs = Nothing






    End Sub

  15. #15
    wnicole is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    118
    Is it possible for me to just get a simpler version in this macro I created. Where I can get code for the To: section.
    I just need to [First Name] and [Email] from T_Inspectors table to connect with my query that uses the same fields.
    Can I just do this from the macro? Easier for me.
    Last edited by pbaldy; 10-18-2013 at 08:48 AM. Reason: Delete suspect link

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 04-25-2013, 10:36 AM
  2. Replies: 19
    Last Post: 03-22-2013, 06:23 PM
  3. Send Email with Attachment VBA Code
    By kevins in forum Programming
    Replies: 2
    Last Post: 10-03-2012, 01:21 PM
  4. Replies: 1
    Last Post: 02-14-2012, 07:08 PM
  5. Replies: 4
    Last Post: 04-13-2011, 10:11 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