Hi. I was wondering if there was a way to send an email without using the Send Object method for a macro. if you use the macro, you will get this warning: 
I know in VB .NET you have to import an outlook object or w/e it is and then there were methods that allowed you to edit the To, CC, BCC, subject, etc
I was wondering if there is something similar in VBA to do that.
What i want to do is the following:
1) when user clicks "Send Email" button, it opens up MS Outlook
2) it attaches a report
3) fills out the subject
Thanks!
@Jeffrey Tan:
I use similar type functionality all the time, so I created some Code for you that you may find slightly useful. It is relatively simple and uses Automation Code to send an E-Mail and Attachment (Report as HTML) from Access via Outlook. The Code will: - Avoid the Outlook Warning Message.
- Automatically fill in the Recipient, Body, and Subject Fields in the Outlook Window.
- Saves a specified Report as HTML and subsequently attaches it to your E-Mail.
- 'Displays' the Outlook Window as opposed to automatically sending the E-Mail.
- May provide a substitute for vbNewLine in order to avoid the problems that you are currently experiencing.
- Simply set a Reference to the Microsoft Outlook XX.X Object Library, substitute your own Values in the Variable Block, and then fire away.
- Any further questions, feel free to ask.
-
'Provides the Send Mail automation. Send an E-Mail and Attachment from Access via Outlook
-
Dim oLook As Object
-
Dim oMail As Object
-
Dim olns As Outlook.NameSpace
-
Dim strRecipient As String
-
Dim strBody As String
-
Dim strSubject As String
-
Dim strReportName As String
-
-
Set oLook = CreateObject("Outlook.Application")
-
Set olns = oLook.GetNamespace("MAPI")
-
Set oMail = oLook.CreateItem(0)
-
-
'************************** Define your own Values here **************************
-
strRecipient = "JTan@aol.com"
-
strBody = "To be or not to be, " & Chr$(13) & Chr$(10) & "that is the question"
-
strSubject = "Demo Database for Jeffrey Tan"
-
strReportName = "rptEmployees"
-
'*********************************************************************************
-
-
DoCmd.OutputTo acOutputReport, strReportName, acFormatHTML, CurrentProject.Path & _
-
"\" & strReportName & ".htm", False
-
-
With oMail
-
.To = strRecipient
-
.Body = strBody
-
.Subject = strSubject
-
.Attachments.Add CurrentProject.Path & "\" & strReportName & ".htm", False
-
.Display
-
End With
-
-
Set oMail = Nothing
-
Set oLook = Nothing
68 7777
Do you wish to automatically Send the E-Mail or Display the Outlook Screen?
You can't get around that message if you're trying to use Outlook to send the e-mail. If you're in an enterprise set up and they have SMTP, you could use the CDO object to send the e-mail.
@ADezii
good question :P
just display the outlook screen before user hits send email.
@Rabbit
i found something that might do it, but i just want to be able to display the email before the user sends it.
** Snip **
sorry NeoPa.
----
if im doing this via macro how do i skip a line in the message text field? - ="Ticket #: " & [Forms]![User Problem Log]![trouble_no] & " -- " & "Brief Problem: " & [Forms]![User Problem Log]![brief_problem]
i tried vbNewLine, but it doesn't work?
NeoPa 32,534
Expert Mod 16PB
If vbNewLine doesn't work that generally indicates one of two things : - The object doesn't support multiple lines period.
- The object uses a vbLineFeed character for separating lines.
Both would surprise me in this case as vbNewLine includes a vbLineFeed character within it, and the email body (being the closest match I can think of to your reference ' message text') does, typically, contain/handle multiple lines of text.
Yeah neoPa, when I tried vbNewLine, VBA automatically added the [ ] to it. so it must be thinking it's a control or something.
I also have another problem linking a report as an attachment.
the macro opens up a report (Print Single Ticket) and when i try to preview the attachment, the report details for the particular record is not the same. the report somehow picks up the latest record and uses that as an attachment.
I've been scratching my head all over about this. Not sure if it's possible.
Other than that, the macro works fine. Just the attachment of a report that's killing me :)
NeoPa 32,534
Expert Mod 16PB Jeffrey:
Yeah neoPa, when I tried vbNewLine, VBA automatically added the [ ] to it. so it must be thinking it's a control or something.
That sounds more like SQL than VBA. Where are you seeing this exactly?
I'm afraid I'm not really the man to help with your other issues though. I tend to avoid the macro system in Access.
@NeoPa, it's in the macro called 'Send Object'
These are the following fields - Object Type: I selected Report
- Object Name: report name
- Output Format: HTML
- To:
- Cc:
- Bcc:
- Subject:
- Message Text:
- Edit Message: No (this is where you allow it to preview or not)
- Template File: not sure about thsi one
NeoPa 32,534
Expert Mod 16PB
As I suspected then. Nothing to do with VBA (VBA is the only place you'd expect VBA constants to be recognised in).
As I said before, I'm not in any position to help you further with your macro work I'm afraid. My best advice would be to avoid macros in all situations. They are clumsy and inflexible and they give you nothing that VBA can't do better in various ways.
yeah it's kinda limited in terms of what i can do with it.
the only solution i can think of is to somehow right click on the report print preview > send to > mail recipient > and it'll attach as an attachment. other than that, i will also have to look at the References for outlook and see what i can come up with.
NeoPa 32,534
Expert Mod 16PB
I haven't got much, but this link ( Problem with e-mailing from within Access) may get you started at least.
Maybe it's time I started getting into this problem (of emailing from Access). I know it comes up a lot (regularly if not frequently) so I'll see if I can make some time to get better acquainted.
@Jeffrey Tan:
I use similar type functionality all the time, so I created some Code for you that you may find slightly useful. It is relatively simple and uses Automation Code to send an E-Mail and Attachment (Report as HTML) from Access via Outlook. The Code will: - Avoid the Outlook Warning Message.
- Automatically fill in the Recipient, Body, and Subject Fields in the Outlook Window.
- Saves a specified Report as HTML and subsequently attaches it to your E-Mail.
- 'Displays' the Outlook Window as opposed to automatically sending the E-Mail.
- May provide a substitute for vbNewLine in order to avoid the problems that you are currently experiencing.
- Simply set a Reference to the Microsoft Outlook XX.X Object Library, substitute your own Values in the Variable Block, and then fire away.
- Any further questions, feel free to ask.
-
'Provides the Send Mail automation. Send an E-Mail and Attachment from Access via Outlook
-
Dim oLook As Object
-
Dim oMail As Object
-
Dim olns As Outlook.NameSpace
-
Dim strRecipient As String
-
Dim strBody As String
-
Dim strSubject As String
-
Dim strReportName As String
-
-
Set oLook = CreateObject("Outlook.Application")
-
Set olns = oLook.GetNamespace("MAPI")
-
Set oMail = oLook.CreateItem(0)
-
-
'************************** Define your own Values here **************************
-
strRecipient = "JTan@aol.com"
-
strBody = "To be or not to be, " & Chr$(13) & Chr$(10) & "that is the question"
-
strSubject = "Demo Database for Jeffrey Tan"
-
strReportName = "rptEmployees"
-
'*********************************************************************************
-
-
DoCmd.OutputTo acOutputReport, strReportName, acFormatHTML, CurrentProject.Path & _
-
"\" & strReportName & ".htm", False
-
-
With oMail
-
.To = strRecipient
-
.Body = strBody
-
.Subject = strSubject
-
.Attachments.Add CurrentProject.Path & "\" & strReportName & ".htm", False
-
.Display
-
End With
-
-
Set oMail = Nothing
-
Set oLook = Nothing
@ADezii:
That looks really self explanatory. Thanks! I'll give it a try and report back if I have any problems.
@ADezii:
Yep still experiencing that report problem.
It's attaching all the records instead of the specific record i'm on.
I can't seem to figure what I did wrong.
This is my query that the report is based on -
SELECT user_problem_log.*, usr_problem_list.trouble_no, usr_problem_list.date,
-
usr_problem_list.user, usr_problem_list.notes, users.First_Name, users.Last_Name,
-
users.extension, offices.Office_Name, users.group_name, users.email
-
FROM user_problem_log
-
INNER JOIN ((offices INNER JOIN users
-
ON offices.office_number = users.Office)
-
INNER JOIN usr_problem_list ON users.win_id = usr_problem_list.user) ON user_problem_log.trouble_no = usr_problem_list.trouble_no;
-
I designed the report the way I normally do:
- label in report header
- rest of the fields in Detail
Anyway to incorporate this in the code? - [user_problem_log].[trouble_no]=[Forms]![User Problem Log]![Text30]
Text30 is the autonumber field.
The above code is taken form the print macro
Report Name: Sub Tickets-Print via Form
View: Print Preview
Filter Name:
Where Condition: see above
Window Mode: Normal
I believe the reason why the code to attach the report attached everything is because access doesn't know which report it is so it grabs every record?
@Jeffrey Tan:
As previously indicated by NeoPa, this seems to be a purely SQL issue as opposed to VBA. The addition of a WHERE Clause in the SQL Statement may do the trick.
@ADezii
Yeah I don't know where to include that part and somehow tie it along with the report name in the strReportName. This is the part I'm really confused on. :(
OMG LOL I think I got it.
I just added that where clause in the query that the report uses!
I'll try that again and see if it really does work.
The last question I have...
when the attachment of the report is attached, it takes the name of the report name... so in my case it attaches it as
"Sub Email Single Ticket.htm (5kb)"
Can we somehow change the name of that to something else? Thanks a bunch! Really appreciate the help!!
-edit-
nvm got it :D
I just added that where clause in the query that the report uses!
Correctamundo, that's what I was referring to.
Can we somehow change the name of that to something else? Thanks a bunch!
The following Code will provide the Attached Report with a Unique Name based on a Base Name, the Current Date, and the Current Time. Pay special attention to Code Line Numbers: 10, 21, 25 and 31: - 'Provides the Send Mail automation. Send an E-Mail and Attachment from
-
'Access via Outlook
-
Dim oLook As Object
-
Dim oMail As Object
-
Dim olns As Outlook.NameSpace
-
Dim strRecipient As String
-
Dim strBody As String
-
Dim strSubject As String
-
Dim strReportName As String
-
Dim strRptAttachName As String
-
-
Set oLook = CreateObject("Outlook.Application")
-
Set olns = oLook.GetNamespace("MAPI")
-
Set oMail = oLook.CreateItem(0)
-
-
'************************** Define your own Values here **************************
-
strRecipient = "ADezii@aol.com"
-
strBody = "To be or not to be, " & Chr$(13) & Chr$(10) & "that is the question"
-
strSubject = "Demo Database for Jeffrey Tan"
-
strReportName = "rptEmployees"
-
strRptAttachName = "JTs_Report_" & Format$(Now, "mmddyyyy_hhmmss")
-
'*********************************************************************************
-
-
DoCmd.OutputTo acOutputReport, strReportName, acFormatHTML, CurrentProject.Path & _
-
"\" & strRptAttachName & ".htm", False
-
-
With oMail
-
.To = strRecipient
-
.Body = strBody
-
.Subject = strSubject
-
.Attachments.Add CurrentProject.Path & "\" & strRptAttachName & ".htm", False
-
.Display
-
End With
-
-
Set oMail = Nothing
-
Set oLook = Nothing
BTW, how did the vbNewLine substitution work out? You may also want to incorporate Code into the Logic that will DELETE the Report as formatted in HTML after Processing/Attaching it.
@ADezii
I just used the following for the report name attachment -
strReportName = Mid("Email-Single", 7) & " Problem Tracking Ticket # " & [Forms]![User Problem Log]![trouble_no]
-
-
DoCmd.OutputTo acOutputReport, "Email-" & Mid(strReportName, 1, 6), acFormatHTML, CurrentProject.Path & _
-
"\" & strReportName & ".htm", False
-
learned it from another question i asked before :D
And yes the Chr$10 and 13 worked out perfectly! Very nice :D Will keep that one in mind.
Yeah I will have to add code after it attachs the report to delete the HTML file. Is it pretty easy to do that?
-edit-
or how about when it attaches the report, move it to the user's temp folder and let windows deal with it :)
Yeah I will have to add code after it attachs the report to delete the HTML file. Is it pretty easy to do that?
- Be careful not to DELETE the File until after it has been Sent.
- You can DELETE ALL HTML (*.htm) Files in the Currentproject.Path at any time, via:
- 'DELETE ALL HTML (*.htm) Files in the CurrentProject.Path Directory
-
If Dir$(CurrentProject.Path & "\*.htm") <> "" Then Kill CurrentProject.Path & "\*.htm"
@ADezii
what do you mean by #1. Isn't the html file we created the only to be deleted?
I tried to use the following to move the file to another folder, but I get an error saying the file already exists - Name CurrentProject.Path & "\" & strReportName & ".htm" As "C:\Documents and Settings\jtan\Desktop\folder"
-edit-
silly me. left out the file name at the end of the new directory. should be - Name CurrentProject.Path & "\" & strReportName & ".htm" As "C:\Documents and Settings\jtan\Desktop\folder" & strReportName & ".htm"
- Dim strSource As String
-
Dim strDestination As String
-
-
strSource = CurrentProject.Path & "\"
-
strDestination = "C:\Documents and Settings\jtan\Desktop\"
-
-
Name CurrentProject.Path & "\" & strReportName & ".htm" As strDestination & strReportName & ".htm"
@ADzeii
Thanks! I guess this problem is now solved :D
You guys are great!!
Hmm another problem now :P
Now what happen's if there are two or more pages of a report? :D
-edit-
the ones with two pages of a report are named with Page2.htm, Page3.htm etc with the report name preceding...
now converting them to a PDF would solve the problem, but I'm not sure if there's such thing as acFormatPDF
but I'm not sure if there's such thing as acFormatPDF
I think that Access 2007 has this option, but if not there are always the *.rtf and *.snp Formats. To me, the *.snp (Snapshot) Format is very impressive. I'm not positive, but I think that the Snapshot Viewer will be installed on Client PCs on first time usage. Rich Text Format is pretty much universal, and usually displays quite well from what I have seen.
@ADezii,
I tried rtf but i dont think it works.
As for SNP, it does work (puts multiple reports in one .snp file), however, ms outlook security disables viewing any .snp file :(
I was thinking to set a count of how many files there are for one specific record and add it to a counter. say if there were 4 pages of record #1, then four would be added and then it would do the
.Attachements.Add ..... Page1.htm until it goes to the last page.
-edit-
hrm.. RTF does work.. but i think in the long run PDF will be best. i did a bit of research and to get ACFORMATPDF to work for 2003, thre is a lot of work to be done :(
How do I determine the number of files in a directory that have certain words in the file name?
I have this function here -
Function countfiles(folder As String)
-
-
Dim directory As String, countOf As Long
-
directory = Dir$(folder & "\*.htm")
-
Do Until directory = ""
-
countOf = (countOf + 1)
-
directory = Dir$()
-
Loop
-
-
MsgBox countOf
-
-
End Function
i want to see the number of htm files that have the words "Single Problem Tracking Ticket #9.htm"
some may have "Single Problem Tracking Ticket #9Page2.htm" Page3, etc
Pass another Argument to the Function that will be the String to search for in the Filename: - Function Definition:
- Function countfiles(folder As String, strStringToSearch As String)
-
Dim directory As String
-
Dim countOf As Long
-
-
directory = Dir$(folder & "\*.htm")
-
-
Do Until directory = ""
-
If InStr(directory, strStringToSearch) > 0 Then
-
countOf = (countOf + 1)
-
End If
-
directory = Dir$()
-
Loop
-
-
MsgBox countOf & " File(s) in " & folder & " contain(s) the String [" & strStringToSearch & "]"
-
End Function
- Sample Call:
- countfiles("<Folder to Search>","Single Problem Tracking Ticket #9.htm")
NeoPa 32,534
Expert Mod 16PB ADezii:
Be careful not to DELETE the File until after it has been Sent.
Generally, a copy of the attachment is stored within your email database (wherever that is on your system) once it's been attached, so that should make it safe to delete once attached. My experience is mainly with Outlook though, so do test this before relying on it 100% ADezii:
You can DELETE ALL HTML (*.htm) Files in the Currentproject.Path at any time, via: - 'DELETE ALL HTML (*.htm) Files in the CurrentProject.Path Directory
-
If Dir$(CurrentProject.Path & "\*.htm") <> "" Then Kill CurrentProject.Path & "\*.htm"
Just a point to mention that web pages often have associated folders to store any images etc that relate to the page. I don't currently have code that does recursive folder tree deletion, but I may work on one when I get a chance.
NeoPa 32,534
Expert Mod 16PB ADezii: - directory = Dir$(folder & "\*.htm")
You may simply want to say (in line #5) : - directory = Dir$(folder & "\" & strStringToSearch & "*.htm")
@NeoPa:
I was thinking more along the lines of Attaching the File, Deleting the File itself, then Canceling the E-Mail. You can now no longer go back to Re-attach the same File since it will no longer exist. Make sense to you, or am I on another one of my Tangents? (LOL).
@ADezii:
I will use your code instead for the search string :D
very nice.
As for the acFormatPDF, i gave up on PDF :P will just attach it as X amount of HTM files if report has X amount of pages.
Somehow, somewhere, MS Outlook is referencing the attachement as a shortcut? And when I send the email (to myself to test), MS outlook blocked it....
The code from yesterday (sending only one file) worked...
I don't know what I did wrong that made MS Outlook get a shortcut of the file.
I'll paste the code I worked on here in the next post.
The first code is a function to see if a file exists or not -
Function FileExists(ByVal strFile As String, Optional bFindFolders As Boolean) As Boolean
-
-
Dim lngAttributes As Long
-
-
'Include read-only files, hidden files, system files.
-
lngAttributes = (vbReadOnly Or vbHidden Or vbSystem)
-
-
If bFindFolders Then
-
lngAttributes = (lngAttributes Or vbDirectory) 'Include folders as well.
-
Else
-
'Strip any trailing slash, so Dir does not look inside the folder.
-
Do While Right$(strFile, 1) = "\"
-
strFile = Left$(strFile, Len(strFile) - 1)
-
Loop
-
End If
-
-
'If Dir() returns something, the file exists.
-
On Error Resume Next
-
FileExists = (Len(Dir(strFile, lngAttributes)) > 0)
-
End Function
-
The next function is to count the files containing the report name excluding the Page2, Page3, etc -
Function countfiles(folder As String)
-
-
Dim directory As String, countOf As Long
-
-
directory = Dir$(folder & "\Single Problem Tracking Ticket # " & [Forms]![User Problem Log]![trouble_no] & "*", vbNormal)
-
Do Until directory = ""
-
countOf = (countOf + 1)
-
directory = Dir$
-
Loop
-
-
countfiles = countOf
-
-
'directory = Dir$(folder & "\Single Problem Tracking Ticket # 9*")
-
End Function
-
This is the code that sets up the email part -
Sub sendEmail()
-
-
'Provides the Send Mail automation. Send an E-Mail and Attachment from Access via Outlook
-
Dim oLook As Object
-
Dim oMail As Object
-
Dim olns As Outlook.NameSpace
-
Dim strRecipient As String
-
Dim strBody As String
-
Dim strSubject As String
-
Dim strReportName As String
-
Dim strSource As String
-
Dim strDestination As String
-
Dim numofFiles As Integer
-
Dim attachfile As String
-
-
Set oLook = CreateObject("Outlook.Application")
-
Set olns = oLook.GetNamespace("MAPI")
-
Set oMail = oLook.CreateItem(0)
-
-
'************************** Define your own Values here **************************
-
strRecipient = ""
-
strBody = ""
-
strSubject = "Problem Tracking Ticket Number: " & [Forms]![User Problem Log]![trouble_no]
-
strReportName = Mid("Email-Single", 7) & " Problem Tracking Ticket # " & [Forms]![User Problem Log]![trouble_no]
-
-
'*********************************************************************************
-
-
'DoCmd.OutputTo acOutputReport, "Email-" & Mid(strReportName, 1, 6), acFormatHTML, CurrentProject.Path & _
-
' "\" & strReportName & ".htm", False
-
-
strSource = CurrentProject.Path & "\"
-
strDestination = "C:\Windows\Temp\"
-
-
If Len(Dir(strDestination, vbDirectory)) = 0 Then 'if directory does not exist
-
-
MkDir (strDestination) 'create it
-
-
End If
-
-
If FileExists(strDestination & strReportName & "*") = False Then 'if file does not exist
-
-
DoCmd.OutputTo acOutputReport, "Email-" & Mid(strReportName, 1, 6), acFormatHTML, CurrentProject.Path & _
-
"\" & strReportName & ".htm", False 'create html file page1, page2, etc
-
-
'numofFiles = countfiles("C:\Windows\Temp")
-
-
numofFiles = countfiles("C:\Documents and Settings\jtan\Desktop\backup")
-
-
If numofFiles > 1 Then
-
Dim i As Integer
-
For i = 2 To numofFiles
-
Name CurrentProject.Path & "\" & strReportName & "Page" & i & ".htm" As strDestination & strReportName & "Page" & i & ".htm" 'move to C:\Windows\Temp
-
Next
-
Name CurrentProject.Path & "\" & strReportName & ".htm" As strDestination & strReportName & ".htm" 'move to C:\Windows\Temp
-
Else
-
Name CurrentProject.Path & "\" & strReportName & ".htm" As strDestination & strReportName & ".htm" 'move to C:\Windows\Temp
-
End If
-
Else 'if file does exist
-
Kill strDestination & strReportName & "*" 'delete it
-
DoCmd.OutputTo acOutputReport, "Email-" & Mid(strReportName, 1, 6), acFormatHTML, CurrentProject.Path & _
-
"\" & strReportName & ".htm", False 'recreate it
-
-
numofFiles = countfiles("C:\Documents and Settings\jtan\Desktop\backup")
-
-
If numofFiles > 1 Then
-
For i = 2 To numofFiles
-
Name CurrentProject.Path & "\" & strReportName & "Page" & i & ".htm" As strDestination & strReportName & "Page" & i & ".htm" 'move to C:\Windows\Temp
-
Next
-
Name CurrentProject.Path & "\" & strReportName & ".htm" As strDestination & strReportName & ".htm" 'move to C:\Windows\Temp
-
Else
-
Name CurrentProject.Path & "\" & strReportName & ".htm" As strDestination & strReportName & ".htm" 'move to C:\Windows\Temp
-
-
End If
-
-
End If
-
-
oMail.To = strRecipient
-
oMail.Body = strBody
-
oMail.Subject = strSubject
-
-
If numofFiles > 1 Then
-
oMail.Attachments.Add strDestination & "\" & strReportName & ".htm", False
-
For i = 2 To numofFiles
-
oMail.Attachments.Add strDestination & "\" & strReportName & "Page" & i & ".htm", False
-
Next
-
Else
-
oMail.Attachments.Add strDestination & "\" & strReportName & ".htm", False
-
-
End If
-
-
oMail.Display
-
-
'With oMail
-
' .To = strRecipient
-
' .Body = strBody
-
' .Subject = strSubject
-
' .Attachments.Add strDestination & "\" & strReportName & ".htm", False
-
' .Display
-
'End With
-
-
Set oMail = Nothing
-
Set oLook = Nothing
-
-
End Sub
sorry for the sloppiness
Is .Attachments add attaching a shortcut or the file directly?
^ problem with MS outlook restricting the ones that are shortcuts.
nvm about the previous code.
this is the updated one -
Sub sendEmail()
-
-
'Provides the Send Mail automation. Send an E-Mail and Attachment from Access via Outlook
-
Dim oLook As Object
-
Dim oMail As Object
-
Dim olns As Outlook.NameSpace
-
Dim strRecipient As String
-
Dim strBody As String
-
Dim strSubject As String
-
Dim strReportName As String
-
Dim strSource As String
-
Dim strDestination As String
-
Dim numofFiles As Integer
-
Dim title As String
-
-
Set oLook = CreateObject("Outlook.Application")
-
Set olns = oLook.GetNamespace("MAPI")
-
Set oMail = oLook.CreateItem(0)
-
-
'************************** Define your own Values here **************************
-
strRecipient = ""
-
strBody = ""
-
strSubject = "Problem Tracking Ticket #: " & [Forms]![User Problem Log]![trouble_no]
-
strReportName = Mid("Email-Single", 7) & " Problem Tracking Ticket # " & [Forms]![User Problem Log]![trouble_no]
-
-
'*********************************************************************************
-
-
strSource = CurrentProject.Path & "\"
-
strDestination = "C:\Documents and Settings\jtan\Desktop\Files\"
-
title = "Single Problem Tracking Ticket # "
-
-
If Not FileExists(strDestination) Then
-
MkDir (strDestination)
-
End If
-
-
If FileExists(strDestination & title & [Forms]![User Problem Log]![trouble_no] & "*") Then
-
'deletes all files related to that trouble #
-
Kill strDestination & title & [Forms]![User Problem Log]![trouble_no] & "*"
-
DoCmd.OutputTo acOutputReport, "Email-" & Mid(strReportName, 1, 6), acFormatHTML, strDestination & _
-
"\" & strReportName & ".htm", False 'create html file page1, page2, etc
-
Else
-
DoCmd.OutputTo acOutputReport, "Email-" & Mid(strReportName, 1, 6), acFormatHTML, strDestination & _
-
"\" & strReportName & ".htm", False 'create html file page1, page2, etc
-
End If
-
-
With oMail
-
.To = strRecipient
-
.Body = strBody
-
.Subject = strSubject
-
-
numofFiles = countfiles(strDestination)
-
-
If numofFiles > 1 Then
-
'adds first page (i.e. Single Problem Tracking Ticket # 9.htm"
-
.Attachments.Add strDestination & "\" & strReportName & ".htm", False
-
'if more than 2 htm files
-
Dim i As Integer
-
For i = 2 To numofFiles
-
'adds page 2 and on (i.e. Single Problem Tracking Ticket # 9Page2.htm, Page3.htm, etc)
-
.Attachments.Add strDestination & "\" & strReportName & "Page" & i & ".htm", False
-
Next
-
Else
-
.Attachments.Add strDestination & "\" & strReportName & ".htm", False
-
End If
-
.Display 'display ms outlook
-
End With
however, MS outlook is still saying it's a shortcut and blocks it. :(
and problem is solved. :)
supervisor decided to migrate over to 2007 so PDF is the way to go since there's an acFormatPDF :).
NeoPa 32,534
Expert Mod 16PB
I would say one of the very few real benefits introduced in 2007 was the acFormatPDF option.
@NeoPa: I definitely agree...
I don't like the tabs on top and it makes finding things a lot harder...
if MS kept with one UI and just changed some features, everyone would be happy :D
Now I can use this docmd.outputto for my other reports and attach em as PDFs :D.
Thanks everyone who helped me once again!
NeoPa 32,534
Expert Mod 16PB Jeffrey:
if MS kept with one UI and just changed some features, everyone would be happy :D
So happy in fact, that far fewer would be bothering to keep up with buying all the new releases ;-)
@NeoPa or @ADezii
i am having problems sending the email from my windows xp laptop. i installed office 2007 and converted the database to 2007. my colleague tried it on his windows 7 desktop and was able to send the email.
When i open access 2007 and open up the form and click on the email button, i get the following error:
Run-time erro '2282':
The format in which you are attempting to output the current object is not available.
anyone know what this means?
Thanks!
- Make sure that your Output Format is set to:
- Referring to your prior attempts in Attaching the *.htm Files, try changing all occurrances of .htm in the Code to .html.
@ADezii
yeah i changed them all to acFormatPDF, but weird how im still getting an error..
i was thinking it could be a missing reference, but i checked the references my collegue has and it's the same.
NeoPa 32,534
Expert Mod 16PB
If that doesn't enable you to find it by yourself, post the current code and indicate which line triggers the error.
-
If FileExists(strDestination & title & [Forms]![User Problem Log]![trouble_no] & "*") Then
-
Kill strDestination & title & [Forms]![User Problem Log]![trouble_no] & "*"
-
DoCmd.OutputTo acOutputReport, "Email-" & Mid(strReportName, 1, 6), acFormatPDF, strDestination & _
-
"\" & strReportName & ".pdf", False
-
Else
-
DoCmd.OutputTo acOutputReport, "Email-" & Mid(strReportName, 1, 6), acFormatPDF, strDestination & _
-
"\" & strReportName & ".pdf", False
-
End If
line #6-7... when i click on the button to email, it just breaks on that line...
it's weird since i have adobe acrobat installed, pdf writer and all that.
Did you make sure you have the folder "C:\Documents and Settings\jtan\Desktop\Files\" on your laptop?
Also, in your code, you have strDestination & "\" . Which means you get "C:\Documents and Settings\jtan\Desktop\Files\\"
@Rabbit: there is code above that creates the directory if it does not exist. sorry forgot to add that in post - If Not FileExists(strDestination) Then
-
MkDir (strDestination)
-
End If
originally, the strDestination was C:\Windows\Temp\.
I have a feeling it's got something to do with Adobe PDF on my machine.
during the day, i downloaded this template from microsoft called "call tracker" and there was this button that had email formats http://office.microsoft.com/en-us/te...i:TC010206879|
I clicked on the button, but i do not see Adobe PDF on it.. so that's the thing I'm confused about.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dave |
last post by:
hi guys
I m trying to execute few lines code tht i have copies
from microsoft tech script centre.
basically its to send email without using any smtp
service. u can find the code snippet from...
|
by: jdph40 |
last post by:
I'm using Access 97. In the OnClick event of a button I have the code
below. I looks at txtEmail and sends an e-mail message without
further action from the user (user does not have to click Send...
|
by: Ronny Sigo |
last post by:
Hello all,
Can anyone tell me how to prevent my mailprog to display the mail, and just
send it ?
The code I use is below
Any help appreciated ..
Thanks
Ronny Sigo
Private Declare Function...
|
by: Mike |
last post by:
In VB6 I could send email via Outlook without using SMTP, Is it possible to
do the same in .NET and if so is there any examples of doing this?
|
by: CLEAR-RCIC |
last post by:
I want to send an email from our Intranet site to myself whenever an error
happens. Our manager will not let us install SMTP on the web server. Is it
possible to send email programatically...
|
by: ErwinF |
last post by:
Hi there,
I would like to know the following:
How to send send email attachments using WebDAV in VB .NET? Sample code please...................
Thanks for your help.
|
by: Siv |
last post by:
Hi,
A little while ago I wrote a small program that allowed the user to view
products from a database. The database holds the details of the products
which can be viewed via a form and...
|
by: win |
last post by:
Please answer me.
Thanks.
|
by: Boki |
last post by:
Hi All,
I want to create a program that auto send out email ( not email bomb )
to myself.
I tried the MAPI, but it will show a notiifcation message, user need
to confirm that.
My target is...
|
by: phill86 |
last post by:
Hi
I am using the following code to send an email from access via outlook automatically
DoCmd.SendObject acSendReport, stDocName, acFormatRTF, "User", , , , , False
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |