2017-10-12 67 views
0

我想从MS Access窗体插入数据到表中,所以我敲了一个简短的函数来查看它是否可能。插入OLE对象的正确类型是什么?

我所拥有的功能是这样的:

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"))

什么是co OLEObject的正确类型?我已经尝试了几个所有的结果。我无法找到哪个DataTypeEnum看起来是正确的类型。

感谢

+0

我只是做插入使用记录集。请参阅[本页](https://www.experts-exchange.com/questions/20129881/How-do-I-insert-an-OLE-object-into-a-database-using-ADO.html) –

+0

可能重复[如何从文件创建一个ole对象 - 女士访问](https://stackoverflow.com/questions/6328395/how-to-create-an-ole-object-from-a-file-ms-访问) – June7

回答

0

当你跳过参数P3,查询将尝试插入IMG(即现在的第三个参数),以A3,从而错误。

相关问题