Access 2007 を使用しており、mySQL データベースにリンクされたテーブルがいくつかあります。DAO を使用してレコードを mySQL リンク テーブルに挿入し、Select @@identity を使用して挿入された PK を取得しようとしていますが、その選択は 0 を返しています。
Dim sql As String
Dim oDB As Database
Set oDB = CurrentDb
sql = "INSERT INTO Quotes ( CustomerID ) SELECT 1 AS Expr1;"
oDB.Execute sql
If oDB.RecordsAffected <> 1 Then
MsgBox "cannot create new quote"
Exit Function
End If
Dim rsNewID As DAO.Recordset
Set rsNewID = oDB.OpenRecordset("SELECT @@IDENTITY") ' Create a recordset and SELECT the new Identity
Dim intNewID As Long
intNewID = rsNewID(0).Value ' Store the value of the new identity in variable intNewID
'This value is 0, why?
このような別の質問を見たことがありますが、満足のいく回答が得られていません