【发布时间】:2017-11-05 11:32:43
【问题描述】:
我有以下代码:
Sub OutputExpences()
Dim strPath As String
Dim FileName As String
Dim TodayDate As String
TodayDate = Format(Date, "DD-MM-YYYY")
strPath = Application.CurrentProject.Path & "\Temp\"
FileName = "Report-Date_" & TodayDate & ".xlsx"
DoCmd.OutputTo acOutputForm, "frmExpences", acFormatXLSX, strPath & FileName, False
'*** Check Network Connection ***
If IsInternetConnected() = True Then
''' connected
EmailToCashier
Else
''' no connected
End If
'*** Check Network Connection ***
Kill strPath & FileName
End Sub
Public Sub EmailToCashier()
Dim mail As Object ' CDO.MESSAGE
Dim config As Object ' CDO.Configuration
Dim strPath As String
Dim FileName As String
Dim TodayDate As String
TodayDate = Format(Date, "DD-MM-YYYY")
strPath = Application.CurrentProject.Path & "\Temp\"
FileName = "Report-Date_" & TodayDate & ".xlsx"
Set mail = CreateObject("CDO.Message")
Set config = CreateObject("CDO.Configuration")
config.Fields(cdoSendUsingMethod).Value = cdoSendUsingPort
config.Fields(cdoSMTPServer).Value = "smtp value"
config.Fields(cdoSMTPServerPort).Value = 465
config.Fields(cdoSMTPConnectionTimeout).Value = 10
config.Fields(cdoSMTPUseSSL).Value = "true"
config.Fields(cdoSMTPAuthenticate).Value = cdoBasic
config.Fields(cdoSendUserName).Value = "email value"
config.Fields(cdoSendPassword).Value = "password value"
config.Fields.Update
Set mail.Configuration = config
With mail
.To = "email"
.From = "email"
.Subject = "subject"
.TextBody = "Thank you."
.AddAttachment strPath & FileName
.Send
End With
MsgBox "Email successfully sent!", vbInformation, "EMAIL STATUS"
Set config = Nothing
Set mail = Nothing
End Sub
我需要等待(用户不能按任何东西或做任何事情)直到所有代码完成。
EmailToCashier 正在将输出文件发送到电子邮件,因此需要时间(2-15 秒,具体取决于网络连接和文件大小)。
谢谢。
【问题讨论】:
-
您的问题是什么?为什么要将表单导出到 Excel 工作簿?
-
你可能需要修改的相关函数是
EmailToCashier。请编辑您的问题并添加其代码。 -
由于 Access 是一个单线程应用程序,在 sub 结束之前,不是所有内容都“锁定”在表单上吗?除非 EmailToCashier 涉及 vbScript.Run 某处...
-
更新代码,请看。
-
有趣。来自here:所有 CDO 方法都是同步的。 -- 所以它应该已经按照你的意愿运行了。
标签: vba ms-access wait cdo.message