2017-09-19 9 views
1

私のVBAは以下のようなものでなければならないと思いますが、動作しません。 「1つまたは複数の必須パラメータに値が指定されていません」というエラーメッセージが表示されます。Excelからのアクセステーブルのレコードを更新しようとしています

Sub Execute_UpdateQuery() 
    Dim NumOfRec As Integer 
    Dim strPath As String 
    Dim rCell As Range 
    Dim rRng As Range 
    Dim sht As Worksheet 
    Dim LastRow As Long 

    DBFullName = ThisWorkbook.Path & "\Stakeholder.accdb" 

    Set cn = CreateObject("ADODB.Connection") 
    cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & DBFullName & ";" 

NumOfRec = 0 
Dim i As Integer, j As Integer 

With Worksheets("Temp") 
Set sht = ThisWorkbook.Worksheets("Temp") 
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row 

i = 11 
    Set rRng = Sheet1.Range("A11:A" & LastRow) 
    For Each rCell In rRng.Cells 
     For j = 2 To 8 
     Debug.Print .Cells(i, j).Value 
      TheUpdate = .Cells(10, j).Value 
      cn.Execute "UPDATE ALLL_HISTORY SET " & TheUpdate & " = '" & .Cells(i, j).Value & _ 
        "' WHERE DESC1 = " & "'" & .Cells(i, 1).Value & "'", , adExecuteNoRecords 
      NumOfRec = NumOfRec + 1 
     Next j 
    i = i + 1 
    Next rCell 
End With 

MsgBox (NumOfRec & " records were updated.") 
cn.Close 
Set conn = Nothing 
End Sub 

これらの画像が役立ちます。

enter image description here

enter image description here

間違っている可能性がどのように任意の考え?これはかなり近いはずです!

+0

どのラインがエラーを送出していますか? – BruceWayne

+2

'DESC1'フィールドがテキストのように見えます。一重引用符で更新値をラップしてみてください。 'WHERE DESC1 = '"&.Cells(i、1).Value& "'" 'アクセスはテキスト型の列で必要です。 –

+2

何がわからないのですか?あなたが 'LLR_Product'のために持っているカラムタイプは' cn.Execute "UPDATE ALLL_HISTORY SET"&TheUpdate& "=" "&.Cells(i、j).Value&" 'WHERE DESC1 = "&.Cells(i 、1).Value、NumOfRec、adExecuteNoRecords' – Zac

答えて

3

3-SYNをSQLに渡すと、numeric value 3 minus value of SYNとして解析されます。SYNは列名ではないため、パラメータと見なされます。

このエラーは、そのパラメータが見つからないことを示しています。渡す値を引用符で囲むことは、SQLにテキストであることを伝え、問題を解決するはずです。

cn.Execute "UPDATE ALLL_HISTORY SET " & TheUpdate & " = '" & .Cells(i, j).Value & _ 
     "' WHERE DESC1 = " & .Cells(i, 1).Value, NumOfRec, adExecuteNoRecords 
+0

ええ、そうでした。 – ryguy72

関連する問題