2017-10-12 95 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,從而錯誤。