VBA电子邮件循环以在Microsoft Access中发送报告

时间:2017-04-07 19:54:04

标签: vba loops email ms-access ms-access-2010

请帮助我一直在努力解决这个问题一周。

我在Microsoft Access中运行了一个报告,我正在尝试创建一个按钮,该按钮将向8个不同的人发送8个报告,而不必单击发送(或编辑消息)。 我在查询中创建了一个表单,其中包含我在我的代码中引用的8个引用(ADC)和电子邮件地址,我在下面附上。 我现在的主要问题是:

  
      
  1. 当我在DoCmd中输入“False”时,仍然会打开编辑信息。
  2.   
  3. 将相应的ADC报告链接到正确的电子邮件。
  4.   
Private Sub loop_email_Click()


DoCmd.OpenForm FormName:="frm_Looper", View:=acNormal, DataMode:=acFormPropertySettings, WindowMode:=acWindowNormal

Dim Email, ADC

DoCmd.GoToRecord , , acLast
'Forms!frm_Looper![ADC]

Set Email = Forms!frm_Looper!EmailAddress
Set ADC = Forms!frm_Looper!ADC

 DoCmd.SendObject acSendReport, "Report2", acFormatPDF, Email, , , "Quarterback Report " & ADC, "Please do not reply to this address. Automated.", False
  'MsgBox "you successfully sent the last report", vbOKOnly, ""
' now go into the looper

Do While ADC > 1
    DoCmd.GoToRecord , , acPrevious


        'MsgBox "you should be at the previous record", vbOKOnly, ""
      Set Email = Forms!frm_Looper!EmailAddress
Set ADC = Forms!frm_Looper!ADC

 DoCmd.SendObject acSendReport, "Report2", acFormatPDF, Email, , , "Quarterback Report " & ADC, "Please do not reply to this address. Automated.", False
  'MsgBox "you successfully sent the last report", vbOKOnly, ""
' now go into the looper

Loop
'MsgBox "Made it through the loop.", vbOKOnly, ""
End Sub

1 个答案:

答案 0 :(得分:0)

你尝试过类似下面的东西,然后把它放到一个循环中吗?这也会在不打开Outlook编辑器的情况下发送电子邮件:

''''''''''''''
' Send Email '
''''''''''''''

email = User & "@123.com"
strItem = "http://schemas.microsoft.com/cdo/configuration/"
strFrom = "TestEmail@email.com"
strCC = ""

Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = CreateObject("CDO.Message")

With objEmail
    .To = email
    .From = strFrom
    .CC = strCC
    .Subject = "Report Confirmation"
    .textbody = "Hi " & FirstName & vbNewLine & vbNewLine _
                "Your Voice!" & vbNewLine & vbNewLine

With .Configuration.Fields
        .Item(strItem & "sendusing") = 2
        .Item(strItem & "smtpserver") = "mailhost"
        .Item(strItem & "smtpserverport") = 25
        .Update
    End With
    .Send
End With

Set objEmail = Nothing
Set objOutlook = Nothing