Minggu, 06 September 2015

Re: [MS_AccessPros] send email in html format

 

Kevin-


I'm not sure I understand your question.  You are certainly free to delete the file using Kill after sending the email.  In that sense, it's a "temporary" file that needs to exist only until you've copied it into the email.  You can also use FollowHyperLink to open the file in the default browser on the machine.

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Sep 6, 2015, at 2:25 PM, 'zhaoliqingoffice@163.com' zhaoliqingoffice@163.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

John-

So a html file will be created and put into C:\Test\TestReport.html,  my question is: can we open the output html as a preview or a temperary file and then use it in email, and close it after it generates html in email? instead of creating a file out of access? Thanks again.

Kevin


Regards,
Kevin Zhao
 
Date: 2015-09-06 20:09
Subject: Re: [MS_AccessPros] send email in html format
 

Kevin-


Yes, if you dink with the page size, you can make your report output onto one page.

Here's some code to get you started.  It compiles, but I don't guarantee that it works.  I'm using a technique called "late binding" so that you don't even have to have the Outlook library loaded as a reference.  I do that by hand-coding the couple of Outlook constants that the code needs, then using CreateObject to dynamically open a copy of Outlook.  Note that this will send only the first page if the report outputs multiple pages.

Sub SendReportHTML()
Dim strHTML As String, strInput As String
Const olMailItem = 0
Const olFormatHTML = 2
Dim objOlApp As Object, objOlMail As Object

    ' Output the 1-page report to html
    DoCmd.OutputTo acOutputReport, "Customer Address Book One Page", acFormatHTML, "C:\Test\TestReport.html"
    ' Open the resulting file
    Open "C:\Test\TestReport.html" For Input As #1
    ' Create an Outlook session
    Set objOlApp = CreateObject("Outlook.Application")
    ' Start a new email
    Set objOlMail = objOlApp.CreateItem(olMailItem)
    ' Read in the created HTML and put together an output string
    Do While Not EOF(1)  ' Loop until end of file
        ' Get a line from the file
        Input #1, strInput
        ' Add it to the accumulated HTML
        strHTML = strHTML & strInput
    Loop
    ' Close the file
    Close #1
    
    ' Use the mail item for several tasks
    With objOlMail
        .To = "johnv@msn.com"
        .Subject = "HTML Email"
        .BodyFormat = olFormatHTML
        .HTMLBody = strHTML
        .Send
    End With
    
    ' Clear the objects
    Set objOlMail = Nothing
    Set objOlApp = Nothing
    
End Sub


John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Sep 6, 2015, at 1:07 PM, 'zhaoliqingoffice@163.com' zhaoliqingoffice@163.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

John-
Thanks a lot. Would you please give an example in code? Would it be possible to create a long page without break? 

Regards,
Kevin Zhao
 
Date: 2015-09-06 17:53
Subject: Re: [MS_AccessPros] send email in html format
 

Kevin-


The easiest way to do that would perhaps to export the report as HTML then open the file created in code and copy the HTML from it into your mail body line by line.  But if the report has multiple pages, I seem to recall that exporting as HTML creates web pages with buttons to go forward / backward between the pages.  Each page is a separate file.

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Sep 6, 2015, at 11:30 AM, 'zhaoliqingoffice@163.com' zhaoliqingoffice@163.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

John-
For this part: "Enter the message text here."  Is that possible to convert rptReport to html and put it in the mail body?  I have tables in in the report. 
 Thanks,
Kevin


 
Date: 2015-09-06 15:38
Subject: Re: [MS_AccessPros] send email in html format
 
Kevin-

Yes, you can do it using Outlook automation.  Set a reference to the Outlook library in VBA, then use code like this:

Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties.

    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    'Create e-mail item
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
       ' Set recipient
       .To = "Kevin@someMail.com"
       ' Set subject
       .Subject = "A message in HTML format…"
       'Set body format to HTML
       .BodyFormat = olFormatHTML
       .HTMLBody = "<HTML><BODY>Enter the message text here. </BODY></HTML>"
       .Send
    End With
End Sub

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Sep 6, 2015, at 3:07 AM, zhaoliqingoffice@163.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

Dear All,
I have learnt how to send html as attachment by the code below.

DoCmd.SendObject acSendReport,"rptReport", acFormatHTML,To:= Email here, Subject:=, Message:=False

My question is, is that possible to send html in email content, instead of as attachment?

Many thanks,
Kevin








__._,_.___

Posted by: John Viescas <johnv@msn.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (10)

.

__,_._,___

Tidak ada komentar:

Posting Komentar