【发布时间】: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