English 中文(简体)
宏观和电子邮件 查阅报告不是附件
原标题:macro to email Access reports not as an attachment

我不知道VBA。 我是否有办法寄送电子邮件,使报告放在电子邮件的正文中,而不是作为附件? 我目前使用“目标”指挥,并以html格式发送。

最佳回答

如果你使用《展望》,你可以撰写报告或盘问,并使用超声波或雷波迪,那是我测试以来的时期,我希望这仍然有用。

Const ForReading = 1, ForWriting = 2, ForAppending = 3

Dim fs, f
Dim RTFBody
Dim MyApp As New Outlook.Application
Dim MyItem As Outlook.MailItem

DoCmd.OutputTo acOutputReport, "Report1", acFormatRTF, "Report1.rtf"
  DoCmd.OutputTo acOutputQuery, "Query1", acFormatHTML, "Query1.htm"

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.OpenTextFile("Report1.rtf", ForReading)
  Set f = fs.OpenTextFile("Query1.htm", ForReading)
RTFBody = f.ReadAll
  Debug.Print RTFBody
f.Close

Set MyItem = MyApp.CreateItem(olMailItem)
With MyItem
   .To = "abc@def.ghi"
   .Subject = "Subject"
   .RTFBody = RTFBody
     .HTMLBody = RTFBody
End With
MyItem.Display
问题回答

这就是我是如何用SendObject来做的,它把报告作为区域工作组并放在电子邮件的正文中。

Private Sub btnEmail_Click()

    Dim IDnumber As Integer
    Dim Message As String
    Dim EmailTo As String
    Dim FileName As String

     Get the current record s ID Number
    IDnumber = Me![ID]
     set file name and path
    FileName = Environ("USERPROFILE") & "My Documents	emp.html"
     set email address
    EmailTo = "someone@domain.com"

     get form to open a new record
    DoCmd.GoToRecord , , acNewRec

     generate report for the current record entered
    DoCmd.OpenReport "ReportName", acPreview, , "[ID]=" & IDnumber, acHidden
     create HTML file for the report
    DoCmd.OutputTo acOutputReport, "ReportName", acFormatHTML, FileName

     open file
    Open FileName For Input As #1
     read the file into a string
    Message = Input(LOF(1) - 1, 1)
     close the file
    Close 1

     generate email
    DoCmd.SendObject acSendReport, "ReportName", acFormatRTF, EmailTo, , , "Subject", Message
     close the report
    DoCmd.Close acReport, "ReportName"

     suppress errors if file is not there
    On Error Resume Next
     remove file
    Kill FileName

End Sub




相关问题
connect Access via c#

i need to open a connection to a remote access db. in the local environment to the remote acess db is working great . when i run this application from production server (other server) it s fail ...

total two or more values under one ID in SQL

![alt text][1] [1]: http://C:Documents and SettingsAdministratorMy DocumentsMy PicturesAshampoo Magical Snap 2Magical Snap - 2009.11.16 23.07 - 003.jpg In referring to the picture there are ...

How to show File Picker dialog in Access 2007?

I want to show a dialog where the user can pick a file, click OK, and then the path to the file will be saved in the database. I have just one problem, I can t figure out how tho show the dialog ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签