SQL Server int和MS Access VBA long数据类型之间的数据类型转换错误

时间:2019-06-07 12:01:25

标签: sql-server vba ms-access

使用ms Access 2007表单,我试图处理链接的SQL Server 2005表中的特定记录。

'Form code
 Private Sub orderid_DblClick(Cancel As Integer)
 Dim idv As Long
 idv = Me.orderid.Value
 '...
 Call manipulateRecord(idv)
 end sub

 'module code
 Public Sub manipulateRecord(pidp As Long)
     Dim rs0 As Recordset
 Set rs0 = CurrentDb.OpenRecordset(dbSeeChanges, "select * from  tableorders where idorder=" & pidp)
 'this line produces the error "Run-time error '3421' data type conversion error"
 'replacing the query with "select idorder from tableorders where idorder=" & pidp  , produces the same error so that there is a mismatch between sqlserver int and  vba long
 'Setting pidp as integer produces overflow error instead
 '...
 end sub

tableorders是链接的sqlserver 2005表

idorder字段的类型为int

如何在MA Access 2007 VBA中识别SQL Server 2005 int?

1 个答案:

答案 0 :(得分:1)

这与long和int无关-您的参数顺序错误。

CurrentDb.OpenRecordset(dbSeeChanges, "select * from  tableorders where idorder=" & pidp)

必须

CurrentDb.OpenRecordset("select * from  tableorders where idorder=" & pidp, , dbSeeChanges)