【问题标题】:The expression On Click you entered as the event property setting produced the following error: Sorry, an unexpected error occurred您作为事件属性设置输入的 On Click 表达式产生了以下错误:对不起,发生了意外错误
【发布时间】:2022-01-26 17:28:41
【问题描述】:

错误消息继续:

"*表达式可能不会产生宏名称、用户定义函数名称或 [事件过程]。" "*评估函数、事件或宏时可能出错。"

这个数据库是由一位多年前退休的员工编写的,不幸的是我现在被它困住了。上周它还在工作,当然今天它停止工作了。我不确定从哪里开始寻找或如何在 VBA 中进行调试。当用户在字段中输入数据并单击“打印”按钮时,我相信数据会填充到数据源中,然后它将打印报告/收据。打印按钮调用 cmdPrintReceipt_Click() 过程。有人可以给我一些指示或如何在 VBA 中调试吗?非常感谢和快乐的假期!

在此处粘贴代码:

Option Compare Database
Option Explicit

Dim OkPass As Integer, message As String, Response As Integer
Dim nAmount As Integer
Dim Conn As New ADODB.Connection
Dim RS2 As ADODB.Recordset
Dim Total As Long 'Hold receiptNumber for ReceiptLine

Private Sub cmdNoAdd_Click()  'close window without adding a new reacord
'Use the msgbox function to see if user wants to exit this form w/o adding new receipt

Dim Msg, Style, Title, respons
Msg = "Close this window without saving this receipt?"
Style = vbYesNo + vbQuestion + vbDefaultButton2 'Define buttons of message box
Title = "Exit without adding a receipt?" 'Title of the message box
respons = MsgBox(Msg, Style, Title)

    If respons = vbYes Then 'User chose Yes DO NOT ADD the Record
       DoCmd.Close
    Else 'User chose No close the message box and leave frmReceipt Open
    End If
End Sub
Private Sub Form_Load()
    'Clear Total
    Total = 0
End Sub
'****************************************************************************************
'   Main procedure for the form, check first all required fields filled in
'   then Add new records and print receipts.
'****************************************************************************************
Private Sub cmdPrintReceipt_Click()
'Check if all filled in, then
    'Just call the AddReceipt Function
    DoNotClose          'function
      If OkPass <> 9 Then
        Response = MsgBox(message, vbOKOnly, "Information Missing")
        'return focus to the frmReceipt
        txtFirstName.SetFocus
        Exit Sub
      Else
       ' Add the new Receipt record
            Me.lblNoAdd.Visible = False
            Me.cmdNoAdd.Visible = False   'you can't escape after printing receipt.
            
            AddAReceipt ' call AddReceipt function
                   
      
      MsgBox "Please confirm the information you entered is correct", vbOKOnly
      ShowPrint3Button
            'cmdPrint3Button print 3 copies of receipt
      End If
      Exit Sub
 End Sub

【问题讨论】:

  • 我昨天看到了类似的情况,不过对于一个运行 Access 2000 的非常旧的应用程序来说,它需要更新。这可能是由最近的 Windows 更新引起的,因此请检查您的更新历史记录,并在可能的情况下回滚到上一个。我没有这样做,而是使用 Access 365 将应用程序转换为 accdb,然后再次运行(当然还有一些其他不相关的修改)。

标签: vba ms-access ms-access-2016


【解决方案1】:

如果它之前工作多年没有错误,我怀疑调试会有所帮助。
数据库可能已损坏。请尝试以下步骤:

  • 查看 VBA 是否编译
  • 压缩和修复数据库
  • 如果不成功,创建一个新的空白数据库,并从旧数据库中删除所有对象。

此外,当您收到错误消息时,您可以按 Ctrl+Break 并到达导致错误的确切行。祝你好运;-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-10
    • 1970-01-01
    • 2015-07-13
    相关资源
    最近更新 更多