您作为事件属性设置输入的表达式On Click产生了以下错误:很抱歉,发生了意外错误



错误消息继续显示:

"表达式不能产生宏的名称、用户定义函数的名称或[Event Procedure]"评估函数、事件或宏时可能出现错误">

这个数据库是由一位几年前退休的员工编写的,不幸的是,我现在被它卡住了。它上周还在工作,当然今天也停止了。我甚至不知道从哪里开始查找,也不知道如何在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

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

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

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

相关内容

最新更新