我正在尝试将MS Access表单中的数据插入表中,所以我已经敲了一个简短的函数来查看它是否可行。
我的功能是:
Function Module2() As Boolean
On Error GoTo Err_Insert
Dim adoCMD As Object
Dim adoRS As Object
Dim strSQL As String
'Define a query to INSERT a new record into the FE temp table
strSQL = "INSERT INTO [Table1] ([A1],[A2],[A3],[img] VALUES (p1,p2,p3,img);"
'Define attachment to database table specifics
Set adoCMD = CreateObject("ADODB.Command")
With adoCMD
.ActiveConnection = CurrentProject.Connection
.CommandType = adCmdText
.Parameters.Append .CreateParameter("p1", adVarChar, adParamInput, Len(Forms("Form1").Controls("text0").value), Forms("Form1").Controls("Text0").value)
.Parameters.Append .CreateParameter("p2", adBoolean, adParamInput, Len(Forms("Form1").Controls("Check2").value), Forms("Form1").Controls("Check2").value)
'.Parameters.Append .CreateParameter("p3", adVarChar, adParamInput, Len(Forms("Form1").Controls("Combo4").value), Forms("Form1").Controls("Combo4").value)
.Parameters.Append .CreateParameter("img", adLongVarBinary, adParamInput, Len(Forms("Form1").OLEBound6), Forms("Form1").Controls("OLEBound6"))
.CommandText = strSQL
Set adoRS = .Execute
End With
'Return a good return code
Module2 = True
Exit_Insert:
'Clean up the connection to the database
Set adoRS = Nothing
Set adoCMD = Nothing
Exit Function
Err_Insert:
Call MsgBox("Class: Module2, Function: Insert()")
Module2 = False
Resume Exit_Insert
End Function
运行时,我收到以下错误:
Run-time error 3421
Application uses a value of the wrong type for the current operation
并在这一点上打破:
.Parameters.Append .CreateParameter("img", adLongVarBinary, adParamInput, Len(Forms("Form1").OLEBound6), Forms("Form1").Controls("OLEBound6"))
OLEObject的正确类型是什么?我已经尝试了几个同样的结果。我找不到哪个DataTypeEnum看起来是正确的类型。
由于
答案 0 :(得分:0)
当您跳过参数P3时,查询将尝试将 img (现在是第三个参数)插入A3,从而产生错误。