Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Try:



    Dim db As DAO.Database, rs1 As DAO.Recordset

    Post your complete procedure. If you are using Bulzie's example, I do not understand the use of DLookup() on a query object when there is a recordset object of the same data. Also, that DLookup does not have WHERE criteria so it will simply return the first value it encounters in the specified field.

    If you need to combine multiple records, then concatenate within a loop. Something like:

    While Not rs.EOF
    strbody = strBody & rs!field1 & ", " & rs!field2 & ", " & rs!field3 & vbCrLf
    rs.MoveNext
    Wend
    strbody = "Some introductory text here." & vbCrLf & strbody

    DoCmd.SendObject acSendNoObject, , , "timt@gmail.com", , , "subject", strBody, True
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  2. #17
    tcheck is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    131
    Here is the code;

    Dim db As Database, rs1 As Recordset
    Set db = CurrentDb
    Set rs1 = db.OpenRecordset("qry_my_Query")


    rs1.MoveFirst


    Do Until rs1.EOF


    vTermText = DLookup("[Symbol]", "qry_my_Query")
    DoCmd.SendObject acSendQuery, "qry_my_Query", "Excel97-Excel2003Workbook(*.xls)", "email@emailcom", "", "m", "Field", vDailyActivity, True, ""


    rs1.MoveNext
    Loop

  3. #18
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    tcheck just to verify, qry_my_Query has name and date of people who have been terminated correct? And you want to loop though this query and send an email for each person in the list? Do you still want to also send the excel file of this list as an attachment or just the text in the body of the message? How often do you run this as you don't want to repeat sending term emails for same people right?

    June7 is right, if looping using my code you don't need the vTermText line (that was for the 1 time email example), you can get the data from the rs1 record for each loop. Maybe try June7 code if you still having issues.

  4. #19
    tcheck is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    131
    The query will run daily and will have the list in the body of the email as well ass an Excel file. The query has changed slightly,, it's not terminated employees, it's a list of items of new inventory. I re-ran the code and it still stops at

    Set rs1 = db.OpenRecordset("qry_my_query")

    Error 13 Type mismatch


    With the below code.

    Dim db As Database, rs1 As Recordset
    Set db = CurrentDb
    Set rs1 = db.OpenRecordset("qry_my_query")




    rs1.MoveFirst




    Do Until rs1.EOF




    vTermText = DLookup("[Symbol]", "qry_my_query")
    DoCmd.SendObject acSendQuery, "qry_my_query", "Excel97-Excel2003Workbook(*.xls)", "my@email.com", "", "", "Symbol", vDailyActivity, True, ""




    rs1.MoveNext
    Loop

  5. #20
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Is "qry_my_query" the actual query? Can you run it manually with no errors?

    Code should be something like:


    Dim db As Database, rs1 As Recordset '(or you can try June7 DAO line: Dim db As DAO.Database, rs1 As DAO.Recordset)

    Set db = CurrentDb
    Set rs1 = db.OpenRecordset("qry_my_query")

    rs1.MoveFirst

    Do Until rs1.EOF
    DoCmd.SendObject acSendQuery, "qry_my_query", "Excel97-Excel2003Workbook(*.xls)", "my@email.com", "", "", "Symbol", "Put text here " & rs1!Symbol, True, ""
    rs1.MoveNext
    Loop

    Change my@email.com to a valid one. Also after the text, put whatever field you need to display, I picked
    rs1!Symbol. In testing, maybe put your email address to see if it is working.

  6. #21
    tcheck is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    131
    The name of the query is different to protect the client but the query does ope without issue.



    Code should be something like:


    THere is an actual email address in the code.
    Change my@email.com to a valid one. Also after the text, put whatever field you need to display, I picked rs1!Symbol. In testing, maybe put your email address to see if it is working.

  7. #22
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    So if you compile the code above, do you still get the error? If so add the DAO. like June7 example to the Dim line and see if it compiles.

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

Similar Threads

  1. Replies: 3
    Last Post: 12-28-2015, 04:11 PM
  2. Replies: 5
    Last Post: 09-14-2015, 07:24 AM
  3. Send email using CDO, get email addresses from table
    By marvinac1 in forum Programming
    Replies: 3
    Last Post: 12-22-2014, 12:54 PM
  4. Replies: 5
    Last Post: 05-07-2014, 09:25 AM
  5. Replies: 4
    Last Post: 04-13-2011, 10:11 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