Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Email multiple files
Bruno Segers 
    
4 years ago
Hey guys, i wrote some code to send several pdf with an order, and something is wrong with it but i can't find it. The funny thing is that neither access nor outlook throw an error.
- The recordset works and I have tested it in a module.
- When I extract the recordset from the code it works. without the extra attachments of the database of course.
- When I activate the recordset only the file in the first code is created. The code continues but nothing else happens.
Can someone tell me what I'm overlooking.
Dan Jackson  @Reply  
            
4 years ago
Please post a snippet of your code and/or some screenshots showing the work and any errors you get (I know you said no errors shown but do you get a debug option? Clicking that show any of your code highlighted? Anything strange happening?). With what you've put, theres nothing we can diagnose with. Cheers
Troubleshooter
Bruno Segers OP  @Reply  
    
4 years ago

Bruno Segers OP  @Reply  
    
4 years ago

Dan Jackson  @Reply  
            
4 years ago
Cool. Above my knowledge base but i'm sure one of the other guys will get back to you real soon
Bruno Segers OP  @Reply  
    
4 years ago
I also have the code debug no errors appear
Bruno Segers OP  @Reply  
    
4 years ago

Kevin Yip  @Reply  
     
4 years ago
Hi Bruno, the mistake is in the line  oEmail.Attachments = emailattachment .  This only adds the most recent attachment, which replaces the previous one, and that's why you end up with only one attachment.  You need to use the Add method to add additional attachments.  E.g.:

oEmail.Attachments.Add "C:\MyFolder\file1.txt"
oEmail.Attachments.Add "C:\MyFolder\file2.txt"
oEmail.Attachments.Add "C:\MyFolder\file3.txt"
Bruno Segers OP  @Reply  
    
4 years ago
Hi Kevin, thanks for helping me out.
But in the case where I don't use the recordset everything works as it should. And if I do use the recordset, I don't get any results anymore. Not even any errors when using the code and when debugging the code. Now I have zero experience how to implement the results of a recordset in outlook or what so ever.
Bruno Segers OP  @Reply  
    
4 years ago
Hi everyone, I found a working code.
I'll upload a screenshot in a moment.
I still have one small problem with recognizing the ID order number in the SQl statement. I know it has something to do with the correct brackets. If anyone knows the answer right away.... please feel free to share it with me.
Bruno Segers OP  @Reply  
    
4 years ago

Bruno Segers OP  @Reply  
    
4 years ago

Bruno Segers OP  @Reply  
    
4 years ago

Alex Hedley  @Reply  
           
4 years ago
Share the SQL Statement as a string
Bruno Segers OP  @Reply  
    
4 years ago
Hi Alex,
It is true that you must define the variable as a String. I had already tried it in the other direction.
The solution is in the SQL statement.
("SELECT OrderDocumentId, OrderId, OrderDocumentLink, SentLink FROM TblOrderDocuments Where SentLink Like True and OrderId Like Orderid")
This should be the following:
('SELECT OrderDocumentId, OrderId, OrderDocumentLink, SentLink FROM TblOrderDocuments Where SentLink Like True and OrderId = ' & Orderid)
And I changed the variable as follows:
OrderId = Me.ID.Value
And everything works perfectly now. Great tool to have if you need to attach a lot of files somewhere. Now I can also check which files I have sent with every order.
If you would like to have the complete code I would be happy to share it with you.
Juan C Rivera  @Reply  
            
4 years ago
Please share

Thanks
Juan
Bruno Segers OP  @Reply  
    
4 years ago
Private Sub BtnTest_Click()

Dim oApp As New Outlook.Application
Dim oEmail As Outlook.MailItem
Dim rs As DAO.recordset
Dim strpath As String
Dim OrderId As String

OrderId = Me.ID.Value
Set oApp = CreateObject("Outlook.Application")
Set oEmail = oApp.CreateItem(olMailItem)

Set rs = CurrentDb.OpenRecordset("SELECT OrderDocumentId, OrderId, OrderDocumentLink, SentLink FROM TblOrderDocuments Where SentLink Like True and OrderId = " & OrderId)

With oEmail
     If rs.RecordCount > 0 Then
     rs.MoveFirst
     Do While Not rs.EOF
         strpath = rs!OrderDocumentLink
         oEmail.Attachments.Add strpath, olByValue
         DoEvents
         rs.MoveNext
     Loop
     End If
     End With
    oEmail.To = "email address here"
    oEmail.Subject = "Group DE BONTE"
    oEmail.Body = "message body here"
    oEmail.Display

End Sub
Kevin Robertson  @Reply  
          
4 years ago
Shouldn't OrderID be a Long?
Richard Rost  @Reply  
          
4 years ago
I'd certainly make OrderID a long. Anything "ID" is a long. :)
Richard Rost  @Reply  
          
4 years ago
I'd certainly make OrderID a long. Anything "ID" is a long. :)

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 9:53:33 AM. PLT: 0s