11 hours ago: Power and Internet are out in my office due to Hurricane Ian. Click for details.
 
Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Seminars   Templates   TechHelp   Fast Tips   Forums   Help   Contact   Join   Order   Logon  
 
Home > Forums > Access
Access Forum


Back to Access Forum
 

Email multiple files Upload Images   Link  
Bruno Segers 
8 days 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
8 days 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
8 days ago

Bruno Segers
8 days ago

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

Kevin Yip
8 days 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
8 days 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
8 days 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
8 days ago

Bruno Segers
8 days ago

Bruno Segers
8 days ago

Alex Hedley
8 days ago
Share the SQL Statement as a string
Bruno Segers
7 days 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
4 days ago
Please share

Thanks
Juan
Bruno Segers
3 days 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
3 days ago
Shouldn't OrderID be a Long?
Richard Rost
2 days ago
I'd certainly make OrderID a long. Anything "ID" is a long. :)
Richard Rost
2 days ago
I'd certainly make OrderID a long. Anything "ID" is a long. :)
Add a ReplyUpload an Image


Back to Access Forum Comments
 

Start a NEW Conversation
 
Only students may post right now. Click here for more information on how you can set up an account. If you are a student, please LOG ON first.
 
Subscribe
 

Check out these other pages that may be of interest to you:

9/27/2022Report Border
9/26/2022First Day of Month
9/23/2022Before Update
9/22/2022Synchronize Subforms
9/21/2022InputBox
9/20/2022Link Master Fields
9/19/2022DateSerial
9/18/2022Sequential Annual Coding
9/16/2022Scope
9/15/2022Resize Forms
 
 

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
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
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn