Logige sisse Microsofti kontoga
Logige sisse või looge konto.
Tere!
Valige mõni muu konto.
Teil on mitu kontot
Valige konto, millega soovite sisse logida.

Märkus.: Soovime pakkuda teie keeles kõige ajakohasemat spikrisisu niipea kui võimalik. See leht on tõlgitud automaatselt ja sellel võib leiduda grammatikavigu või ebatäpsusi. Tahame, et sellest sisust oleks teile abi. Palun märkige selle lehe allservas, kas sellest teabest oli teile kasu või mitte. Soovi korral saab ingliskeelset artiklit lugeda siit.

Kui seate Accessi vormi atribuudi Tõrke_korral sündmuse protseduuri, ei saa tuua tõrget ODBC selle toimingu kirjeldust, ja ka ei saa ülekatet teatud ODBC tõrge. ODBC tõrke ilmnemisel ainult teave, mis edastatakse tõrge sündmuseprotseduur on arv, Üldine tõrge, näiteks 3146, mis vastab kuvatakse tõrketeade: ODBC-kõne nurjus.

Põhjus

ODBC tõrketeated tavaliselt koosneb kahest osast. Esimene osa on tõrge 3146, mille kirjeldus on:

ODBC-nurjus

Tõrge server kohased teave on esitatud teise komponendi, kust saate otsida tõrke number ja kirjeldust, näiteks:

[Microsoft] [ODBC SQL Server draiveri] [SQL serveri] < Server kohased tõrketeade > (< tõrkenumber > #)

Kui seate vormi atribuudi Tõrke_korral sündmuse protseduuri, te saate ülekatet arvu viga esimene osa, kuid te ei saa ülekatet teise komponendi arv. Teine osa ODBC tõrge server kohased teave ekraanil kuvatakse pärast seda, kui kood on lõpule jõudnud töötab, kui lisate järgmine rida korral toimingut:

Vastuse = acDataErrContinue

Eraldusvõime

Märkus.: Microsoft pakub joonisel ainult ilma garantii kaudseid. See sisaldab, kuid ei ole piiratud, sobivuse või teatud otstarbeks õigsuse. Selles artiklis eeldatakse, et olete tuttav programmeerimiskeel, mis on on näidanud ja tööriistad, mis loomiseks ja silumine toimingutest. Microsofti toe töötajad, aitab mõne konkreetse protseduuri funktsiooni selgitada, kuid nad ei muuda neid näiteid pakkumiseks ega ehitada kord teie konkreetsetele nõuetele.

Saate luua Microsoft Visual Basic, mis kasutab RecordsetClone , mis põhineb vormi värskendada Accessi objektid (DAO). See võimaldab teil ülekatet kuvatakse tõrketeadet.

DAO sisaldab tõrgete kollektsiooni ülekatet teine osa ODBC tõrge server kohased teave kasutavad. ODBC tõrke ilmnemisel esimene osa on talletatud tõrgete saidikogumi esimene element ja teine osa on salvestatud teise elemendi.

Artiklis kirjeldatud näide kasutab BeforeUpdate sündmuse asemel tõrke korral teatud ODBC tõrked. Funktsioon, mis püüab tõrgete ODBC kui BeforeUpdate sündmuse vormi loomiseks tehke järgmist.

  1. Looge tühi töölauaandmebaas.

  2. Link dbo_Accounts näidisandmebaasi AdventureWorks Microsoft SQL serveri tabel.

  3. Kasutage vormiviisardi - piklikku paigutuse kontod tabeli põhjal uue vormi loomine.

  4. Vormi salvestamine frmAccounts.

  5. Luua uue mooduli ja seejärel tippige järgmine rida on deklaratsioonijaotis kui sellel real ei ole juba olemas.

    Konkreetsete suvand

  6. Tippige või kleepige mooduli järgmist:

    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. Kordumatu nimi mooduli salvestage ja sulgege aken mooduli.

  8. Seadke frmAccounts vormi atribuudile sündmuse järgmist:

    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. Klõpsake menüü silumine , kompileerida < andmebaasi nimi >

  10. Kui tõrkeid ei teki, salvestage vorm.

  11. Saate avada frmAccounts vormi ja seejärel uue kirje lisamiseks või kirje redigeerimiseks.

    Kui teete muudatuse kirjele, salvestatakse kirje, kui teisaldate mõne muu kirje. ODBC tõrke ilmnemisel kuvatakse tõrge server kohased põhineva kohandatud teade ja selle üldise "ODBC – kutse nurjus" sõnum on seob.

Kas vajate veel abi?

Kas soovite rohkem valikuvariante?

Siin saate tutvuda tellimusega kaasnevate eelistega, sirvida koolituskursusi, õppida seadet kaitsma ja teha veel palju muud.

Kogukonnad aitavad teil küsimusi esitada ja neile vastuseid saada, anda tagasisidet ja saada nõu rikkalike teadmistega asjatundjatelt.

Kas sellest teabest oli abi?

Kui rahul te keelekvaliteediga olete?
Mis mõjutas teie hinnangut?
Kui klõpsate nuppu Edasta, kasutatakse teie tagasisidet Microsofti toodete ja teenuste täiustamiseks. IT-administraator saab neid andmeid koguda. Privaatsusavaldus.

Täname tagasiside eest!

×