简体   繁体   中英

Errors with linked tables and Ms Access ( Run-time error '3622' : dbSeeChanges/Identity column )

I am trying to output the name of all linked tables, including their fields which are Date/Time, and that fields values.

The following code can output the first table, field name and their first value, not all values, although when it gets to the next linked table, I get this error

Run-time Error '3622' 
You must use the dbSeeChanges option with OpenRecordSet when accessing a SQL Server table that has an IDENTITY column.

Here is my code

Private Sub btnGetFields_Click()

   Dim db As DAO.Database
   Dim tdf As DAO.TableDef
   Dim f As Field
   Dim rst As DAO.Recordset
   Dim numField As Integer

   Set db = CurrentDb

   For Each tdf In db.TableDefs

        If Left$(tdf.Connect, 9) = "ODBC;DSN=" Then

            Set rst = CurrentDb.OpenRecordset(tdf.Name)
            numField = rst.Fields.Count

            Debug.Print "Table: " & tdf.Name
            For index = 0 To numField - 1
                 If rst.Fields(index).Type = dbDate Then

                     Debug.Print "Field: " & rst.Fields(index).Name; "   Value : "; rst.Fields(index).Value
                 End If
            Next



        End If

   Next

   Set tdf = Nothing
   Set db = Nothing

End Sub

I read something that if I'm using sql tables I should use ADO? Any ideas?

You can continue to use your existing DAO code, just change

Set rst = CurrentDb.OpenRecordset(tdf.Name)

to

Set rst = CurrentDb.OpenRecordset(tdf.Name, dbOpenSnapshot)

That opens a static read-only Recordset, so dbSeeChanges is not required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM