Page 2 of 2 FirstFirst 12
Results 16 to 29 of 29
  1. #16
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,525
    In the VBA editor, go into Tools/References and check the MS Outlook library.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  2. #17
    kierandobson is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2017
    Posts
    15
    Quote Originally Posted by pbaldy View Post
    In the VBA editor, go into Tools/References and check the MS Outlook library.
    Click image for larger version. 

Name:	error.PNG 
Views:	14 
Size:	42.1 KB 
ID:	29318

    Thanks, but now I am getting a new error?

    Thanks again

  3. #18
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    Ooops. I did not test or even run debugger on code. My Bad.

    Instead of Wend, use Loop or remove 'Do' so the While...Wend will work. I am always getting those mixed up.

    Review http://www.worldbestlearningcenter.c...2010-Loops.htm
    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.

  4. #19
    kierandobson is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2017
    Posts
    15
    Quote Originally Posted by June7 View Post
    Ooops. I did not test or even run debugger on code. My Bad.

    Instead of Wend, use Loop or remove 'Do' so the While...Wend will work. I am always getting those mixed up.

    Review http://www.worldbestlearningcenter.c...2010-Loops.htm
    Excellent, this works!

    Now, sometimes, the files have not saved so occasionally the file it is looking for may not be there. All I need now is some form of error handling within the loop that will simply move onto the next record if said file does not exist. I have tried a few methods on google but not getting anywhere. What and where do I need in this code to do this?

    Code:
    Private Sub EndDay_Click()
            Dim appOutLook As Outlook.Application, mailOutLook As Outlook.MailItem, rs As DAO.Recordset
        Set appOutLook = CreateObject("Outlook.Application")
        Set mailOutLook = appOutLook.CreateItem(olMailItem)
        Set rs = CurrentDb.OpenRecordset("SELECT SubNo FROM SubconListT WHERE OrderDate = Date();")
        With mailOutLook
            Do While Not rs.EOF
                .Attachments.Add "C:\Users\Ryan\Desktop\" & rs!SubNo & ".pdf"
                rs.MoveNext
            Loop
            .To = "k.dobson93@gmail.com"
            .Subject = "subject text here"
            .HTMLBody = "message body here"
            .Display
        End With
    End Sub
    Finally getting somewhere, thanks for all your help

  5. #20
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    If Dir("C:\Users\Ryan\Desktop" & rs!SubNo & ".pdf") <> "" Then .Attachments.Add "C:\Users\Ryan\Desktop" & rs!SubNo & ".pdf"
    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.

  6. #21
    kierandobson is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2017
    Posts
    15
    Quote Originally Posted by June7 View Post
    If Dir("C:\Users\Ryan\Desktop" & rs!SubNo & ".pdf") <> "" Then .Attachments.Add "C:\Users\Ryan\Desktop" & rs!SubNo & ".pdf"
    Thanks, no error message but now there are no attachments on the email. I feel we are on the right track though.

    Thanks again

  7. #22
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    Google: Access vba references early late binding

    Here is one:

    http://excelmatters.com/2013/09/23/v...-late-binding/

    The disadvantage to late binding is don't get IntelliSense popup help. So build your code with early binding and then if you want to distribute db with late binding just change the Dim statements and remove the library reference before distribution.
    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.

  8. #23
    kierandobson is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2017
    Posts
    15
    Ah my bad, it does work. Now for hopefully my final question.

    The query I am basing this off is paramater based, and the paramater is selected from a combo box in a form. I know this involves query defs and such but how would I slot this in to my code? The combo box is in a form called MainMenuF. The combo box is labelled SupplierLookup and the parameter is all of my different suppliers.

    Code:
    Private Sub EndDay_Click()
    
            Dim appOutLook As Outlook.Application, mailOutLook As Outlook.MailItem, rs As DAO.Recordset
        Set appOutLook = CreateObject("Outlook.Application")
        Set mailOutLook = appOutLook.CreateItem(olMailItem)
        Set rs = CurrentDb.OpenRecordset("SELECT SubNo FROM SupplierLookupQ WHERE OrderDate = Date();")
        With mailOutLook
            Do While Not rs.EOF
                If Dir("C:\Users\Ryan\Desktop\" & rs!SubNo & ".pdf") <> "" Then .Attachments.Add "C:\Users\Ryan\Desktop\" & rs!SubNo & ".pdf"
                rs.MoveNext
                Loop
            .To = ""
            .Subject = "Orders Raised Today"
            .HTMLBody = "Hello <br> <br> Please see attached all of the orders we have raised today with you. You will be receiving these the next working day. This is a new system I am trying out so you are aware of what you will be receiving off us, and perhaps any necessary preparation can be made prior to you receiving these orders. If you cannot hit the date requested on the Purchase Order, I would be grateful if you could advise me at the earliest opportunity. To follow this up I will send over a list of all of our orders with you once a week, as I am aware that things change and a date may have to change for whatever reason. You will be scored based on you meeting the dates you have told us that you will meet. If we have no update, you will be scored against the date we requested. <br> <br> My aim with this new system is to make both of our jobs easier, and to work more fluently together. <br> <br> Many Thanks. <br> <br> Kieran"
            .Display
        End With
    End Sub

  9. #24
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    I never user dynamic parameterized queries.

    So SupplierLookupQ is a query. Post its SQL statement.

    Where is the email procedure located?
    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.

  10. #25
    kierandobson is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2017
    Posts
    15
    Quote Originally Posted by June7 View Post
    I never user dynamic parameterized queries.

    So SupplierLookupQ is a query. Post its SQL statement.

    Where is the email procedure located?
    I am not sure what you mean about the email procedure, but the SQL code is as follows:
    Code:
    SELECT SubconListT.Supplier, SubconListT.Explanation, SubconListT.SubNo, SubconListT.WorksOrder, SubconListT.DueDate, SubconListT.DateModified, SubconListT.TimeModified, SubconListT.PartNo, SubconListT.Customer, SubconListT.QTY, SubconListT.Notes, SubconListT.[Collected/Despatched], SubconListT.ProjectedCompletionDate, SubconListT.OrderDate, SupplierListT.SupplierNotes, SupplierListT.Contact, SupplierListT.ContactNo, SupplierListT.SupplierID, SubconListT.JavelinUpdate
    FROM SupplierListT INNER JOIN SubconListT ON SupplierListT.SupplierID = SubconListT.Supplier
    WHERE (((SupplierListT.SupplierID)=[Forms]![MainMenuF]![SupplierLookup]))
    ORDER BY SubconListT.Supplier, SubconListT.SubNo;

  11. #26
    kierandobson is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2017
    Posts
    15
    Quote Originally Posted by June7 View Post
    I never user dynamic parameterized queries.

    So SupplierLookupQ is a query. Post its SQL statement.

    Where is the email procedure located?
    The email procedure is located in a form called LookupF. Apologies, I think I have just understood your last reply.

  12. #27
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,951
    Set rs = CurrentDb.OpenRecordset("SELECT SubNo FROM SubconListT WHERE Supplier=" & [Forms]![MainMenuF]![SupplierLookup] & " AND OrderDate = Date();")

    This will, of course, pull records only for the current day. If you want to be able to pull for any date, will have to modify this code to refer to a control on form where user can specify date.
    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.

  13. #28
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    answered - didn't see

  14. #29
    kierandobson is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jun 2017
    Posts
    15
    Quote Originally Posted by June7 View Post
    Set rs = CurrentDb.OpenRecordset("SELECT SubNo FROM SubconListT WHERE Supplier=" & [Forms]![MainMenuF]![SupplierLookup] & " AND OrderDate = Date();")

    This will, of course, pull records only for the current day. If you want to be able to pull for any date, will have to modify this code to refer to a control on form where user can specify date.
    This is exactly what I want! It works perfectly, thank you very much for all your help.

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

Similar Threads

  1. Replies: 2
    Last Post: 03-16-2017, 08:34 PM
  2. Send Multiple csv attachments by email
    By shaunacol in forum Import/Export Data
    Replies: 16
    Last Post: 07-20-2015, 12:22 PM
  3. Send email with attachments not empty
    By JJCHCK in forum Programming
    Replies: 3
    Last Post: 09-23-2011, 10:29 AM
  4. Send email with attachments
    By rbiggs in forum Programming
    Replies: 12
    Last Post: 07-23-2011, 12:50 PM
  5. Send Report and Attachments in Email
    By Pimped in forum Programming
    Replies: 1
    Last Post: 06-21-2011, 02:51 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