Pick and email a specific file (.ics) in a directory? (1 Viewer)

Ole

Registered User.
Local time
Today, 15:45
Joined
Apr 15, 2012
Messages
32
Hi

I've created an .ics file (which is working perfectly) and saved it in C:\iCalender. The file is called "SendToTechiCalendar795" were 795 is referring to an errand number.
Since I can't use the same method as when I email .pdf files, I need to make this workaround (save the file first).
I can't figure out how to pick that specific file and send it as an attachment to a specific recipient.
It's mostly the "picking" and "attach to email" method I can't figure out.

Code:
-----
Private Sub SendToTech_Click()
On Error GoTo SendToTech_Err

Dim stLinkCriteria As String
Dim File As String
Dim MailTo As Integer
Dim intSearch As String
Dim Filename As String
Dim FileName2 As String
Dim NewAttachmentName As String
Dim SubjectEmail As String
Dim MailAtt As String


Filename = "C:\ErrandSend\SendToTechiCalendar" & Me!Turnr & ".ics"
SubjectEmail = "New errand " & Me!Turnr & ""
MailAtt = TDUFORMAT
File = "SendToTechiCalendar"
NewAttachmentName = SubjectEmail

DoCmd.OutputTo acOutputReport, File, acFormatTXT, Filename, False
DoCmd.OpenReport File, acViewPreview, , , acHidden
Reports(File).Caption = NewAttachmentName
DoCmd.OpenReport File, acViewPreview, , stLinkCriteria, , acWindowNormal
DoCmd.SendObject acReport, File, "PDFFormat(*.pdf)", MailAtt, "ole.traulsen@gmail.com", "", SubjectEmail, "Hereby a new errand ", True, ""

MsgBox "The errand is saved in C:\ErrandSend\SendToTechiCalendar and emailed to fitter", vbOKOnly, "Information"

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

'stLinkCriteria = "Turnr=" & Me!Turnr
'FileName2 = "C:\Errands\Closed Errand " & Me!Turnr & "- " & Date & ".pdf"
'DoCmd.OutputTo acOutputReport, DeliveryNote, acFormatTXT, FileName2, False
'MsgBox "The specification has been saved in C:\Errands", vbOKOnly, "Information"
'DoCmd.Close acReport, DeliveryNote, acSaveYes

SendToTech_Exit:
Exit Sub

SendToTech_Err:
MsgBox "The task can't be preformed right now.", vbOKOnly, "Error message"
Resume SendToTech_Exit


End Sub
-----

Any Ideas?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:45
Joined
Oct 29, 2018
Messages
21,358
Hi. Did you mean "manually" picking the file using the file browser, or your code "automatically" picks it?
 

Ole

Registered User.
Local time
Today, 15:45
Joined
Apr 15, 2012
Messages
32
Hi. Did you mean "manually" picking the file using the file browser, or your code "automatically" picks it?

I would like the code to pick it automatically - then i'll work as a flow.
Create .ics file, pick it and email it.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:45
Joined
Oct 29, 2018
Messages
21,358
I would like the code to pick it automatically - then i'll work as a flow.
Create .ics file, pick it and email it.
Hmm, let me get this straight. I just looked at your code. Are you saying the email you're sending has a PDF attachment and you would like to add the ICS file as another attachment to the same email?
 

Ole

Registered User.
Local time
Today, 15:45
Joined
Apr 15, 2012
Messages
32
Hmm, let me get this straight. I just looked at your code. Are you saying the email you're sending has a PDF attachment and you would like to add the ICS file as another attachment to the same email?
The PDF is just a tryout to ser if I could do some adjustments to send the ics instead.
 

Ole

Registered User.
Local time
Today, 15:45
Joined
Apr 15, 2012
Messages
32
It is very easy to automate Outlook if that is your email client, many examples in this forum and Google. Or use CDO if you use Gmail or other clients.
Cheers,
I would very much like to send as code in Access instead of Outlook. I honestly don’t understand how the Outlook automation works. But I am using Outlook, so if I can be guided I’m ready to try.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:45
Joined
Oct 29, 2018
Messages
21,358
The PDF is just a tryout to ser if I could do some adjustments to send the ics instead.
Hi. In the code you posted above, you have this line:

DoCmd.OutputTo acOutputReport, File, acFormatTXT, Filename, False

Does it actually produces the ICS file for you? If so, then rather than use this as a test:
Code:
DoCmd.SendObject acReport, File, "PDFFormat(*.pdf)", MailAtt, "ole.traulsen@gmail.com", "", SubjectEmail, "Hereby a new errand ", True, ""
Try this one instead:
Rich (BB code):
DoCmd.SendObject acReport, File, acFormatTXT, MailAtt, "ole.traulsen@gmail.com", "", SubjectEmail, "Hereby a new errand ", True, ""
 

Ole

Registered User.
Local time
Today, 15:45
Joined
Apr 15, 2012
Messages
32
Hi. In the code you posted above, you have this line:

DoCmd.OutputTo acOutputReport, File, acFormatTXT, Filename, False

Does it actually produces the ICS file for you? If so, then rather than use this as a test:
Code:
DoCmd.SendObject acReport, File, "PDFFormat(*.pdf)", MailAtt, "ole.traulsen@gmail.com", "", SubjectEmail, "Hereby a new errand ", True, ""
Try this one instead:
Rich (BB code):
DoCmd.SendObject acReport, File, acFormatTXT, MailAtt, "ole.traulsen@gmail.com", "", SubjectEmail, "Hereby a new errand ", True, ""

Here is the code which produce the .ics file.
I've tried to use...acFormatTXT, but it didn't work.
That's why I need to grab the file directly from the directory - if it's possible.

The "DoCmd.SendObject acReport, File, "PDFFormat(*.pdf)", MailAtt, "ole.traulsen@gmail.com", "", SubjectEmail, "Hereby a new errand ", True, "" " is for testing.
 

Ole

Registered User.
Local time
Today, 15:45
Joined
Apr 15, 2012
Messages
32
I tried to look into the Outlook code, but Access won't recognize the code?!
There must be a way to grab the file in the directory and attach it to an email generated from Access - at least I hope so
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:45
Joined
Oct 29, 2018
Messages
21,358
Here is the code which produce the .ics file.
I've tried to use...acFormatTXT, but it didn't work.
That's why I need to grab the file directly from the directory - if it's possible.

The "DoCmd.SendObject acReport, File, "PDFFormat(*.pdf)", MailAtt, "ole.traulsen@gmail.com", "", SubjectEmail, "Hereby a new errand ", True, "" " is for testing.
Hi. Did you forget to include the code that produces the .ics file? I don't see it.
 

Ole

Registered User.
Local time
Today, 15:45
Joined
Apr 15, 2012
Messages
32
Hi. Did you forget to include the code that produces the .ics file? I don't see it.
No - it's quite easy. I simple made a report with the necessary information and saves it as a .ics file. No rocket science :)
I've attached the .txt file which I saved as an .ics file.

But I got the Outlook part to work as bastanu asked me to.

So thank you all for your input - now I need to figure out how to change the "Set objOutlookRecip = .Recipients.Add("ole.traulsen@gmail.com")" to Set objOutlookRecip = .Recipients.Add(MailAtt) instead. meaning that I would like to be able to change the recipients(!)
 

Attachments

  • SendToTechiCalendar 795.txt
    955 bytes · Views: 451

theDBguy

I’m here to help
Staff member
Local time
Today, 07:45
Joined
Oct 29, 2018
Messages
21,358
No - it's quite easy. I simple made a report with the necessary information and saves it as a .ics file. No rocket science :)
I've attached the .txt file which I saved as an .ics file.

But I got the Outlook part to work as bastanu asked me to.

So thank you all for your input - now I need to figure out how to change the "Set objOutlookRecip = .Recipients.Add("ole.traulsen@gmail.com")" to Set objOutlookRecip = .Recipients.Add(MailAtt) instead. meaning that I would like to be able to change the recipients(!)
Hi. Please understand, we can't see what you're doing; and sometimes, little details help us get a clue on how to help you. So, my "real" question was, "exactly how are you saving the report as a .ics file?" I mean, did you use code like the OutputTo method, or did you do it manually? If manually, what were the steps you took?

Now, if you're happy with your current solution (although I thought you said you wanted to avoid using Outlook, if you can), then you can choose not to answer the above questions.

.Recipients.Add(MailAtt) should work as long as MailAtt = "ole.traulsen@gmail.com"

Good luck!
 

Ole

Registered User.
Local time
Today, 15:45
Joined
Apr 15, 2012
Messages
32
Hi. Please understand, we can't see what you're doing; and sometimes, little details help us get a clue on how to help you. So, my "real" question was, "exactly how are you saving the report as a .ics file?" I mean, did you use code like the OutputTo method, or did you do it manually? If manually, what were the steps you took?

Now, if you're happy with your current solution (although I thought you said you wanted to avoid using Outlook, if you can), then you can choose not to answer the above questions.

.Recipients.Add(MailAtt) should work as long as MailAtt = "ole.traulsen@gmail.com"

Good luck!
The code is:
DoCmd.OutputTo acOutputReport, File, acFormatTXT, Filename, False
No secret there :)

My problem is that ".Recipients.Add(MailAtt) should work as long as MailAtt = "ole.traulsen@gmail.com"" doesn't quite work.
It seems like I can't transfer MailAtt from my Class Object to the Module. So if I change the value of MailAtt it doesn't "follow" to the Module.
 

Users who are viewing this thread

Top Bottom