Kirjaudu sisään Microsoft-tilillä
Kirjaudu sisään tai luo tili.
Hei,
Käytä toista tiliä.
Sinulla on useita tilejä
Valitse tili, jolla haluat kirjautua sisään.

Huomautus: Microsoft haluaa tarjota sinulle ajantasaisinta ohjesisältöä mahdollisimman nopeasti omalla kielelläsi. Tämä sivu on käännetty automaation avulla, ja siinä saattaa olla kielioppivirheitä tai epätarkkuuksia. Tarkoitus on, että sisällöstä on sinulle hyötyä. Kertoisitko sivun alareunassa olevan toiminnon avulla, oliko tiedoista hyötyä? Tästä pääset helposti artikkelin englanninkieliseen versioon.

Jos Access-lomakkeen VirheenYhteydessä-ominaisuuden arvoksi tapahtumatoimintosarja, ei voi hakea ODBC-virhe menettely kuvaus ja et voi etsiä myös ODBC-virheestä. Kun ODBC-virhe ilmenee, vain tiedot, jotka siirretään virhe tapahtumatoimintosarja on Yleinen virhe, kuten 3146, joka vastaa virhesanoma määrä: ODBC-kutsu epäonnistui.

Syy

ODBC-virhesanomia koostuvat tavallisesti kaksi osaa. Ensimmäinen osa on virhe 3146, jonka kuvaus on:

ODBC-kutsu epäonnistui

Serverin virhetiedot sisältyvät toinen osa, josta voit hakea virhenumero ja kuvaus, kuten:

[Microsoft] [ODBC SQL Server-ohjain] SQL Server < Serverin virhesanoma > (#< virhenumero >)

Jos lomakkeen VirheenYhteydessä -ominaisuuden arvoksi tapahtumatoimintosarja, voit etsiä virheen ensimmäisen osan numero, mutta ei voi etsiä toisen osan numero. ODBC-virhe toisen osan Serveriä koskevia tietoja näkyy näytössä jälkeen koodin suorittaminen on valmis, ellet sisällytä seuraava rivi, ohjeiden mukaisesti:

Vastauksen = acDataErrContinue

Tarkkuus

Huomautus: Microsoft toimittaa ohjelmoinnin esimerkkejä vain ilmaistuna tai implisiittinen. Tämä sisältää, mutta ei ole tarkasteltavana, epäsuora takuita kaupalliseen käytettävyyteen tai johonkin tiettyyn tarkoitukseen. Tässä artikkelissa oletetaan, että olet perehtynyt ohjelmointikieli, joka on parhaillaan osoitettu ja työkaluja, joiden avulla voit luoda ja virheenkorjaus ohjeita. Microsoftin tukihenkilöt voivat auttaa tietyn toiminnon toimintoja, mutta he eivät muokkaa näitä esimerkkejä toimintoja tai käyttää menetelmiä erityistarpeita.

Voit luoda Microsoft Visual Basic for Applications-toimintosarjan, joka päivittää RecordsetClone , joka perustuu lomakkeen käyttämällä Data Access Objects (DAO). Voit etsiä, näyttöön tulee virhesanoma.

DAO sisältää virheet -sivustokokoelman, jonka avulla voi etsiä toisen osan ODBC-virhe Serverin tiedot. ODBC-virhe ilmenee, kun ensimmäinen osa on tallennettu virheitä sivustokokoelman ensimmäinen elementti ja toinen osa on tallennettu toinen osa.

Tämän artikkelin esimerkissä käytetään sijaan Error -tapahtuma ennen päivittämistä -tapahtumaa voi etsiä tietyn ODBC-virheet. Voit luoda funktion, joka luo ODBC virheistä, kun lomakkeen ennen päivittämistä -tapahtuman ilmetessä seuraavasti:

  1. Luo tyhjä työpöytätietokanta.

  2. Linkki dbo_Accounts AdventureWorks mallitietokannassa Microsoft SQL Server-taulukko.

  3. Ohjatulla lomakkeen luomisella - Sarakemuoto asettelua, jotta Asiakkaat-taulukkoon perustuva uuden lomakkeen luominen.

  4. Lomakkeen tallentaminen frmAccounts.

  5. Luo uusi moduuli ja kirjoita sitten seuraavan rivin määrittelyosa Jos riville ei ole vielä lisätty:

    Eksplisiittinen asetus

  6. Kirjoita tai liitä moduulia seuraavasti:

    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. Tallenna moduuli on yksilöllinen nimi ja sulje moduuli-ikkunasta.

  8. FrmAccounts lomakkeen ennen päivittämistä -ominaisuuden arvoksi tapahtuman seuraavasti:

    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. Valitse Virheenkorjaus -valikosta Käännä < tietokannan nimi >

  10. Jos virheitä ilmenee, Tallenna lomake.

  11. Avaa frmAccounts-lomake ja Lisää uusi tietue tai tietueen muokkaaminen.

    Kun teet muutoksen tietueen, tietue on tallennettu, kun siirryt toiseen tietueeseen. Jos ODBC-virhe ilmenee, näet mukautettu sanoma, joka perustuu Serverin-virhe, ja Yleinen ”ODBC: kutsu epäonnistui” viesti on osa liukuväriä.

Tarvitsetko lisäohjeita?

Haluatko lisää vaihtoehtoja?

Tutustu tilausetuihin, selaa harjoituskursseja, opi suojaamaan laitteesi ja paljon muuta.

Osallistumalla yhteisöihin voit kysyä kysymyksiä ja vastata niihin, antaa palautetta sekä kuulla lisää asiantuntijoilta, joilla on runsaasti tietoa.

Oliko näistä tiedoista hyötyä?

Kuinka tyytyväinen olet käännöksen laatuun?
Mikä vaikutti kokemukseesi?
Kun valitset Lähetä, palautettasi käytetään Microsoftin tuotteiden ja palveluiden parantamiseen. IT-järjestelmänvalvojasi voi kerätä nämä tiedot. Tietosuojatiedot.

Kiitos palautteesta!

×