아무도 정말로 귀하의 질문에 답변하지 않았습니다. 당신이 무시하고자하는 오류를 결정하기 위해 오류 처리기에서 SELECT CASE를 사용,이 코드에서
Public Sub MySub()
On Error GoTo errHandler
Dim rs As DAO.Recordset
Set rs = CurrentDB.OpenRecords([SQL SELECT])
If rs.RecordCount >0 Then
rs.MoveFirst
Do Until rs.EOF
[do whatever that produces the error]
errSkipToNext:
rs.MoveNext
Loop
End If
exitRoutine:
If Not (rs Is Nothing) Then
rs.Close
Set rs = Nothing
Exit Sub
errHandler:
Select Case Err.Number
Case X, Y, Z ' where these are error numbers you want to ignore
Err.Clear
' do whatever it is you need to do in order to record the offending row
Call RecordError(rs!PK, Err.Number) ' PK is a field that identifies the bad record
GoTo errSkipToNext
Case Else
MsgBox Err.Number & ": " & Err.Description, vbExclamation, _
"Error!"
Resume exitRoutine
End Select
End Sub
:
은 당신의 코드는 다음과 같은 (골격 프레임 워크)를 말한다. 위의 코드 프레임 워크에서 오류 번호를 X, Y, Z
으로 나열했지만 대신 무시할 실제 오류 번호로 바꾸십시오.
모든 단일 오류를 무시하고 싶지 않을 수 있습니다. 중요한 오류는 서브 루틴의 다른 위치에서 무시할 수 있기 때문입니다. 제한된 오류 수를 파악하고 싶지 않으면 무시할 오류를 생성하는 코드 블록의 시작 부분에 플래그를 설정 한 다음 `If bolErrorInCodeBlockToIgnore 그런 다음 모든 오류를 무시하는지 여부를 결정하십시오. 이런 식으로 뭔가 : 나는이 알려진 오류 발생하지 오래된 오류를 무시에 확고한 신자 해요로
Public Sub MySub()
On Error GoTo errHandler
Dim rs As DAO.Recordset
Dim bolErrorInCodeBlockToIgnore As Boolean
Set rs = CurrentDB.OpenRecords([SQL SELECT])
If rs.RecordCount >0 Then
rs.MoveFirst
Do Until rs.EOF
bolErrorInCodeBlockToIgnore = True
[do whatever that produces the error]
errSkipToNext:
rs.MoveNext
Loop
End If
exitRoutine:
If Not (rs Is Nothing) Then
rs.Close
Set rs = Nothing
Exit Sub
errHandler:
If bolErrorInCodeBlockToIgnore Then
Err.Clear
' do whatever it is you need to do in order to record the offending row
Call RecordError(rs!PK, Err.Number) ' PK is a field that identifies the bad record
bolErrorInCodeBlockToIgnore = False
GoTo errSkipToNext
Else
MsgBox Err.Number & ": " & Err.Description, vbExclamation, _
"Error!"
Resume exitRoutine
End If
End Sub
나는 훨씬 첫번째를 선호하는 것입니다. 그러나 무시하고 싶은 모든 오류를 생성하는 테스트를 찾는 것은 매우 어려울 수 있습니다.
표시되는 오류 메시지의 예를 제공 할 수 있습니까? –
오류 메시지가 적절하지 않습니다. 오류는 내 데이터베이스 필드의 형식과 관련이 있으며'On Error GoTo ... '를 설정하지 않으면 얻을 것으로 예상되는 오류 메시지입니다. 사실 내가 설정 한 레이블로 이동하지 않고 코드가 손상되고 있습니다. – rdevitt
내가 묻는 이유는 VBA를 사용하여 트래핑 할 수없는 Access에서 트리거 된 오류 메시지가 있기 때문입니다. –