【问题标题】:Run-time error '-2147352567 (80020009)' No Current Record MySQL back-end DAO recordset运行时错误 '-2147352567 (80020009)' No Current Record MySQL 后端 DAO 记录集
【发布时间】:2013-10-12 14:01:37
【问题描述】:

我将一个数据库的后端 MS Access 2003 升级到 MySQL 5.1。 我正在将后端 MYSQL 5.1 数据库通过 ODBC(MySQL ODBC 5.1 驱动程序)链接到 MS Access 前端 .mdb。

我正在使用 DAO 记录集。我使用 .AddNew 方法添加新记录并使用

进行更新

.更新方法;在更新语句之后,我将自动编号字段提取到变量中,该变量给出了

“运行时错误'-2147352567 (80020009)'没有当前记录”错误。

但相同的代码在具有 MS-Access 2003 后端的旧版本中也可以工作。

'new 
if bNew  = true then
    lngInvoiceID = 0
else 'edit , 
    lngInvoiceID = Forms("frmInvoice").[tbInvoiceID].value
end if


Set rstAux = dbsLocal.OpenRecordset("Select * from tblElectronicInvoices where
eipID = " & lngInvoiceID, dbOpenDynaset, dbSeeChanges)

rstAux.AddNew

rstAux.Update
lngInvoiceID = Nz(rstAux.Fields("eipID"), 0)

'当我尝试取回自动编号字段的 eipID 时,出现没有当前记录错误。

以前的 MS Access 代码可以访问后端链接表到前端。 dbSeeChanges 的选项没有指定,在更新语句之前,我可以获得自动编号字段的新 ID。

【问题讨论】:

    标签: mysql ms-access dao autonumber mysql-odbc-connector


    【解决方案1】:

    几年前,在将后端数据库从 Access 迁移到 MySQL 后(将前端保留在 Access 中),我遇到了同样的情况。我最终使用了以下解决方法:

    Dim cdb As DAO.Database, qdf As DAO.QueryDef, rst As DAO.Recordset
    Dim lngCustomerID As Long
    Set cdb = CurrentDb
    
    ' create pass-through query to insert new row and then retrieve the IDENTITY value
    Set qdf = cdb.CreateQueryDef("")
    qdf.Connect = cdb.TableDefs("customers").Connect  ' get .Connect from existing linked table
    qdf.ReturnsRecords = False
    qdf.SQL = "INSERT INTO customers (customerName) VALUES ('GordCo')"
    qdf.Execute
    qdf.ReturnsRecords = True
    qdf.SQL = "SELECT LAST_INSERT_ID()"
    Set rst = qdf.OpenRecordset(dbOpenSnapshot)
    lngCustomerID = rst(0).Value
    Debug.Print "LAST_INSERT_ID() returned " & lngCustomerID
    rst.Close
    Set rst = Nothing
    Set qdf = Nothing
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-11
      相关资源
      最近更新 更多