晚上的伙伴们!我在处理access中的vba错误时遇到了问题。当发生错误时,它工作得很好,问题是sub将执行所有的事情,而我总是以错误消息结束,即使我根本没有错误!代码:
Private Sub SaveEmployee_Click()
On Error GoTo Err_handlar
If List7.ListCount = 0 Then
Dim dial As String
dial = MsgBox("No employee was chosen. Quit the process?", vbYesNo, "No Entry!")
If dial = vbYes Then
DoCmd.Close
End If
Else
Dim i As Integer
Dim record As Recordset
Dim lname As String
Dim query As String
ReDim employeelist(List7.ListCount - 1)
For i = 0 To List7.ListCount - 1
lname = Right(List7.ItemData(i), Len(List7.ItemData(i)) - InStrRev(List7.ItemData(i), " "))
query = "Select EmployeeID from 0TBL_Employees where FirstName =trim('" + Left(List7.ItemData(i), Len(List7.ItemData(i)) - Len(lname)) + " ') and LastName=trim('" + lname + "')"
Set record = CurrentDb.OpenRecordset(query)
employeelist(i) = record!EmployeeID
Next i
For i = 0 To 1
MsgBox employeelist(i)
Next i
DoCmd.Close
End If
Err_handlar:
MsgBox "Error during doing the operation, please contact M&E unit!", vbOKOnly, "Fatal Error"
Exit Sub
End Sub发布于 2015-04-30 21:22:07
您的msgbox行必须放在Err_handlar:之前,以便正常操作在msgbox之前退出。
https://stackoverflow.com/questions/29968129
复制相似问题