【发布时间】:2015-04-30 12:45:07
【问题描述】:
晚上好朋友! 我在处理访问中的 vba 错误时遇到问题。发生错误时它工作正常,问题是子程序将执行所有内容,即使我根本没有错误,我总是会收到错误消息! 代码:
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
【问题讨论】:
标签: ms-access error-handling vba ms-access-2007