【问题标题】:Microsoft Access / VBA and Outlook - crashesMicrosoft Access / VBA 和 Outlook - 崩溃
【发布时间】:2020-09-13 05:57:54
【问题描述】:

我们正在尝试构建一个 Access 应用程序。首先,它将更新数据条目,然后生成 Outlook 应用程序。 它会更新数据,但会因为 Outlook 而崩溃(这就是我们的想法)。

我们尝试过的:

  • 早绑定/晚绑定
  • DoEvents
  • 调试找出在哪一步会崩溃,但在调试模式下不会崩溃
  • DoCmd.SendObject

我们的代码:

Private Sub cmd_Freigegeben_Click()
 Dim OutApp As Outlook.Application
    Dim OutMail As Outlook.MailItem
    Dim strbody As String
    Dim sname As String
    Dim sTo As String
    Dim sSAP As String
    Dim sFRE As String
    Dim sFile As String
    Dim iClick As String

     sTo = Me.txt_EMail.Value
     sSAP = Me.txt_SAP.Value
     sFRE = Me.txt_FreigabeID

  Dim FlName As String
    sFile = Me.txt_Link
    sFile = Replace(sFile, "\\file01\", "W:\")

       FlName = sFile

If FlName = "" Then
    MsgBox "Bitte wähle einen Datensatz aus!", vbOKOnly, "Vorsicht"
    Exit Sub
End If
 iClick = MsgBox( _
         prompt:="Die Änderung dieses Datensatzes mit der SAP-Nummer:  (" & sSAP & ") und mit der Freigabe-ID:  (" & sFRE & ") wird gestartet, möchtest du fortfahren?", _
         Buttons:=vbYesNo, Title:="FREIGEGEBEN")
   If iClick = vbYes Then
     GoTo UPDATE
   ElseIf iClick = vbNo Then
     Exit Sub
   End If

UPDATE:
 Call mod_update.freigegeben_update

    On Error GoTo Fehler
    Set OutApp = New Outlook.Application
    Set OutMail = OutApp.CreateItem(olMailItem)

    strbody = "Hallo," & vbNewLine & vbNewLine & "ich habe dir folgende Wohnung mit der SAP-Nummer freigegeben: " & sSAP & vbNewLine & vbNewLine & "LG :)"

    With OutMail
        .To = sTo
        .Subject = Me.cbo_Freigabeliste.Value & " Freigabe - " & sSAP & " , Freigabe-ID: " & sFRE
        .Body = strbody
        .display
    End With

    Set OutMail = Nothing
    Set OutApp = Nothing
    Call Felder_Leeren


Fehler:
    If Err.Number <> 0 And Err.Number <> 40040 Then MsgBox "OMG! Da ist was falsch! Bitte melden!" & vbCrLf & "Fehler: " & Err.Number, vbCritical, "Computer sagt nein :("
End Sub

也许有人遇到过这种情况并且知道该怎么做? (我们花了 2 天时间寻找解决方案)

谢谢!

【问题讨论】:

  • 将日志消息写入文本文件以找出崩溃的确切位置。
  • mod_update.freigegeben_update 是什么?
  • 谢谢@Andre,现在我们发现它在另一个步骤中崩溃了
  • 感谢@ThomasG,我们发现错误在于将记录集绑定到列表框导致崩溃...但我们可能有解决方案:)

标签: vba ms-access outlook


【解决方案1】:

在处理 Outlook 对象模型时,您似乎遇到了一个标准的安全问题。为了确保只是尝试用.Display 替换.Send 方法。有几个选项可用:

  1. 使用最新的防病毒软件(此时 Outlook 不会显示提示)
  2. 使用构建 Outlook 的低级代码 - 扩展 MAPI。您可以考虑使用任何使用扩展 MAPI 的包装器,例如 Redemption。
  3. 类似ClickYes 或Outlook security manager 的产品允许禁止显示此类警告或提示。
  4. 部署组策略以防止触发问题。

【讨论】:

  • 感谢您的评论 :) 我会检查的 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多