Microsoft로 로그인
로그인하거나 계정을 만듭니다.
안녕하세요.
다른 계정을 선택합니다.
계정이 여러 개 있음
로그인할 계정을 선택합니다.

참고: 사용자 언어로 가능한 한 빨리 가장 최신의 도움말 콘텐츠를 제공하고자 합니다. 이 페이지는 자동화를 통해 번역되었으며 문법 오류나 부정확한 설명을 포함할 수 있습니다. 이 목적은 콘텐츠가 사용자에게 유용하다는 것입니다. 이 페이지 하단의 정보가 도움이 되었다면 알려주세요. 쉽게 참조할 수 있는 영어 문서가 여기 있습니다.

이벤트 프로시저 Access 폼의 OnError 속성을 설정 하는 경우 해당 절차에 ODBC 오류 설명을 검색할 수 없습니다 및 특정 ODBC 오류를 트래핑 수 없습니다. ODBC 오류가 발생 한 오류 이벤트 프로시저에 전달 되는 유일한 정보는 일반 오류, 3146, 예: 오류 메시지에 해당 하는 번호로: ODBC-호출에 실패 했습니다.

원인

ODBC 오류 메시지의 두 가지 구성 요소 일반적으로 구성 됩니다. 첫 번째 구성 요소가 오류 3146, 설명이 됩니다.

ODBC 호출 하지 못했습니다.

오류 번호와 같은 설명을 검색할 수 있는 두 번째 구성 요소에 서버 관련 오류 정보가 포함 되어 있습니다.

[Microsoft] [ODBC SQL Server 드라이버] [SQL Server] < 서버 관련 오류 메시지 > (#< 오류 번호 >)

이벤트 프로시저 폼의 OnError 속성을 설정 하는 경우 첫 번째 구성 요소, 오류의 번호를 트래핑 수 있지만 두 번째 구성 요소 수가 트래핑 수 없습니다. 코드 완료 된 후를 실행 하는 이벤트 다음 줄을 포함 하지 않는 한 절차는 화면에 나타나는 ODBC 오류의 두 번째 부분에서 서버 관련 정보:

응답 acDataErrContinue =

해결 방법

참고: Microsoft는 보증을 포함 하지 않고 설명을을 위한 프로그래밍 예제를 제공 합니다. 이 포함 되지만 목적 또는 특정 목적에 대 한 체력 단련 보증도로 제한 되지 않습니다. 이 문서를 만들고 디버그 절차를 사용 하는 도구 및 여기서 설명 하는 프로그래밍 언어에 익숙한 가정 합니다. Microsoft 기술 지원 엔지니어 특정 프로시저의 기능을 설명할 수 있지만이 예제에서는 추가 기능을 제공 하거나 특정 요구 사항을 충족 하는 절차를 구성 하려면 수정 하지 않습니다.

데이터 액세스 개체 (DAO)를 사용 하 여 양식을 기반 RecordsetClone 업데이트 하는 응용 프로그램 절차에 대 한 Microsoft Visual Basic을 만들 수 있습니다. 이렇게 하면 나타나는 오류 메시지를 처리할 수 있습니다.

DAO는 ODBC 오류의 두 번째 부분에서 서버 관련 정보를 트래핑 하는 데 사용할 수 있는 오류 모음 포함 되어 있습니다. ODBC 오류가 발생 한 경우 첫 번째 구성 요소 오류 모음의 첫 번째 요소에 저장 되 고 두 번째 요소에 두 번째 구성 요소를 저장 합니다.

이 문서의 예제 오류 이벤트 대신 BeforeUpdate 이벤트를 사용 하 여 특정 ODBC 오류를 처리할 수 있습니다. 양식 BeforeUpdate 이벤트가 발생할 때마다 해당 ODBC 오류를 트래핑 하는 함수를 만들려면 다음이 단계를 따릅니다.

  1. 새 데스크톱 데이터베이스를 만듭니다.

  2. Microsoft SQL Server에서 AdventureWorks 예제 데이터베이스의 dbo_Accounts 테이블에 연결 합니다.

  3. 폼 마법사-계정 테이블에 따라 새 폼을 만들려면 세로 레이아웃을 사용 합니다.

  4. FrmAccounts로 폼을 저장 합니다.

  5. 새 모듈을 만들고 해당 행이 없는 경우 선언 섹션에서 다음 줄을 입력 합니다.

    명시적 옵션

  6. 입력 하거나 다음 절차에 따라 모듈에 붙여 넣습니다.

    Public Function SaveRecODBC(SRO_form As Form) As Boolean
    ' ***************************************************************
    ' Function: SaveRecODBC
    ' Purpose: Updates a form based on a linked ODBC table
    ' and traps any ODBC errors.
    ' Arguments: SRO_Form, which refers to the form.
    ' Returns: True if successful or False if an error occurs.
    ' ***************************************************************
    On Error GoTo SaveRecODBCErr
    Dim fld As Field, ctl As Control
    Dim errStored As Error
    Dim rc As DAO.Recordset
    
    ' Check to see if the record has changed.
    If SRO_form.Dirty Then
        Set rc = SRO_form.Recordset.Clone
        If SRO_form.NewRecord Then
            rc.AddNew
            For Each ctl In SRO_form.Controls
                ' Check to see if it is the type of control
                ' that has a ControlSource.
                If ctl.ControlType = acTextBox Or _
                    ctl.ControlType = acComboBox Or _
                    ctl.ControlType = acListBox Or _
                    ctl.ControlType = acCheckBox Then
                    ' Verify that a value exists in the ControlSource.
                    If ctl.Properties("ControlSource") <> "" Then
                        ' Loop through the fields collection in the
                        ' RecordsetClone. If you find a field name
                        ' that matches the ControlSource, update the
                        ' field. If not, skip the field. This is
                        ' necessary to account for calculated controls.
                        For Each fld In rc.Fields
                            ' Find the field and verify
                            ' that it is not Null.
                            ' If it is Null, don't add it.
                            If fld.Name = ctl.Properties("ControlSource") _
                            And Not IsNull(ctl) Then
                                fld.Value = ctl
                                ' Exit the For loop
                                ' if you have a match.
                                Exit For
                            End If
                        Next fld
                    End If ' End If ctl.Properties("ControlSource")
                End If ' End If ctl.controltype
            Next ctl
            rc.Update
        Else
            ' This is not a new record.
            ' Set the bookmark to synchronize the record in the
            ' RecordsetClone with the record in the form.
            rc.Bookmark = SRO_form.Bookmark
            rc.Edit
            For Each ctl In SRO_form.Controls
                ' Check to see if it is the type of control
                ' that has a ControlSource.
                If ctl.ControlType = acTextBox Or _
                    ctl.ControlType = acComboBox Or _
                    ctl.ControlType = acListBox Or _
                    ctl.ControlType = acCheckBox Then
                    ' Verify that a value exists in the
                    ' ControlSource.
                    If ctl.Properties("ControlSource") <> "" Then
                        ' Loop through the fields collection in the
                        ' RecordsetClone. If you find a field name
                        ' that matches the ControlSource, update the
                        ' field. If not, skip the field. This is
                        ' necessary to account for calcualted controls.
                        For Each fld In rc.Fields
                            ' Find the field and make sure that the
                            ' value has changed. If it has not
                            ' changed, do not perform the update.
                            If fld.Name = ctl.Properties("ControlSource") _
                                And fld.Value <> ctl And _
                                Not IsNull(fld.Value <> ctl) Then
                                fld.Value = ctl
                                ' Exit the For loop if you have a match.
                                Exit For
                            End If
                        Next fld
                    End If ' End If ctl.Properties("ControlSource")
                End If ' End If ctl.controltype
            Next ctl
            rc.Update
        End If ' End If SRO_form.NewRecord
    End If ' End If SRO_form.Dirty
    ' If function has executed successfully to this point then
    ' set its value to True and exit.
    SaveRecODBC = True
    
    Exit_SaveRecODBCErr:
        Exit Function
    
    SaveRecODBCErr:
    ' The function failed because of an ODBC error.
    ' Below are a list of some of the known error numbers.
    ' If you are not receiving an error in this list,
    ' add that error to the Select Case statement.
    For Each errStored In DBEngine.Errors
        Select Case errStored.Number
            Case 3146 ' No action -- standard ODBC--Call failed error.
            Case 2627 ' Error caused by duplicate value in primary key.
                MsgBox "You tried to enter a duplicate value in the Primary Key."
            Case 3621 ' No action -- standard ODBC command aborted error.
            Case 547 ' Foreign key constraint error.
                MsgBox "You violated a foreign key constraint."
            Case Else ' An error not accounted for in the Select Case ' statement.
                On Error GoTo 0
                Resume
        End Select
    Next errStored
    SaveRecODBC = False
    Resume Exit_SaveRecODBCErr
    
    End Function
    
  7. 모듈 고유한 이름으로 저장 하 고 모듈 창을 닫습니다.

  8. 다음 이벤트 프로시저 frmAccounts 양식의 BeforeUpdate 속성을 설정 합니다.

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    ' If you can save the changes to the record undo the changes on the form.
    If SaveRecODBC(Me) Then Me.Undo
    ' If this is a new record go to the last record on the form.
    If Me.NewRecord Then
        RunCommand acCmdRecordsGoToLast
    Else
        ' If you can't update the record, cancel the BeforeUpdate event.
        Cancel = -1
    End If
    End Sub
    
  9. 디버그 메뉴에서 < 데이터베이스 이름 > 컴파일 을 클릭합니다

  10. 오류가 발생 한 경우 폼을 저장 합니다.

  11. FrmAccounts 양식을 엽니다 새 레코드를 추가 하거나 레코드를 편집 합니다.

    레코드를 변경할 때 레코드의 다른 레코드로 이동할 때 저장 됩니다. 서버 특정 오류에 기반 하는 사용자 지정 메시지가 표시 ODBC 오류가 발생 하 고 일반 "ODBC-호출에 실패 했습니다" 메시지를 트래핑 합니다.

도움이 더 필요하세요?

더 많은 옵션을 원하세요?

구독 혜택을 살펴보고, 교육 과정을 찾아보고, 디바이스를 보호하는 방법 등을 알아봅니다.

커뮤니티를 통해 질문하고 답변하고, 피드백을 제공하고, 풍부한 지식을 갖춘 전문가의 의견을 들을 수 있습니다.

이 정보가 유용한가요?

언어 품질에 얼마나 만족하시나요?
사용 경험에 어떠한 영향을 주었나요?
제출을 누르면 피드백이 Microsoft 제품과 서비스를 개선하는 데 사용됩니다. IT 관리자는 이 데이터를 수집할 수 있습니다. 개인정보처리방침

의견 주셔서 감사합니다!

×