【问题标题】:Errors with linked tables and Ms Access ( Run-time error '3622' : dbSeeChanges/Identity column )链接表和 Ms Access 错误(运行时错误“3622”:dbSeeChanges/Identity 列)
【发布时间】:2013-06-14 11:00:01
【问题描述】:

我正在尝试输出所有链接表的名称,包括它们的日期/时间字段以及字段值。

下面的代码可以输出第一个表,字段名和它们的第一个值,而不是所有值,虽然当它到达下一个链接表时,我得到这个错误

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

这是我的代码

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

我读到如果我使用 sql 表我应该使用 ADO? 有什么想法吗?

【问题讨论】:

    标签: sql sql-server vba ms-access


    【解决方案1】:

    您可以继续使用现有的 DAO 代码,只需更改

    Set rst = CurrentDb.OpenRecordset(tdf.Name)
    

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

    这会打开一个静态只读记录集,因此不需要dbSeeChanges

    【讨论】:

    • 就是这样!谢谢好心的先生!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    相关资源
    最近更新 更多