我有一個子例程,當我單擊我的窗體上的按鈕時運行。問題是無論發生什麼,錯誤塊都會被執行,我不知道爲什麼。 Access VBA不太好,所以這可能是一個簡單的錯誤。訪問VBA塊時執行它不應該
這裏是我的子:
Public Sub findRecord()
Dim rs As DAO.Recordset
Set rs = Me.[dbo_NCL_SimmonsCodes subform1].Form.Recordset
rs.FindFirst "NCL_ItemNum=""LSIM-" & Me.Text0 & """"
If rs.NoMatch Then
MsgBox "No match found. Please try again." & vbNewLine & vbNewLine & "If this is a new item, please click the Add Record button to add.", vbInformation, "No Match"
End If
On Error GoTo description_Error
Me.lblDescription.Caption = DLookup("Description", "dbo_AL_ItemUPCs", "ItemCode ='" & Me.Text0 & "'")
Exit_FindRecord:
Exit Sub
description_Error:
MsgBox "Error " & Err.Number & ": " & Err.Description & vbNewLine & vbNewLine, vbExclamation, "VBA Error " & Err.Number
Me.lblDescription.Caption = "Error."
Resume Exit_FindRecord
End Sub
我們到達ErrHandler時有什麼Err.Number?它真的是零嗎? –
@Tiago Cardoso - 是的,它是0. – MAW74656
@Tiago Cardoso - 我應該說它應該是0(當dlookup作品找到合適的匹配時),但我根本不應該收到消息框在這些情況下。 – MAW74656