2013-10-12 2 views
1

데이터베이스의 백엔드 MS Access 2003을 MySQL 5.1로 업그레이드했습니다. 백엔드 MYSQL 5.1 데이터베이스 thr 'ODBC (MySQL ODBC 5.1 드라이버) MS 액세스 프런트 엔드 .mdb 연결 중입니다.런타임 오류 '-2147352567 (80020009)'현재 레코드 없음 MySQL 백엔드 DAO 레코드

DAO 레코드 집합을 사용하고 있습니다. .AddNew 메서드를 사용하여 새 레코드를 추가하고

을 사용하여 업데이트합니다 .Update 메서드; 업데이트 성명 후 자동 번호 필드를 가져 오는 변수로 가져옵니다.

"런타임 오류 '-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) 

'autonumber 필드 인 eipID를 다시 가져 오려고하면 현재 레코드 오류가 발생하지 않습니다.

이전 MS 액세스 코드는 프런트 엔드에 백엔드 링크 된 테이블에 액세스 할 수 있습니다. dbSeeChanges의 옵션이 지정되지 않았고 update 문 앞에 autonumber 필드의 새 ID를 얻을 수있었습니다.

답변

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