私の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
これらの画像が役立ちます。
間違っている可能性がどのように任意の考え?これはかなり近いはずです!
どのラインがエラーを送出していますか? – BruceWayne
'DESC1'フィールドがテキストのように見えます。一重引用符で更新値をラップしてみてください。 'WHERE DESC1 = '"&.Cells(i、1).Value& "'" 'アクセスはテキスト型の列で必要です。 –
何がわからないのですか?あなたが 'LLR_Product'のために持っているカラムタイプは' cn.Execute "UPDATE ALLL_HISTORY SET"&TheUpdate& "=" "&.Cells(i、j).Value&" 'WHERE DESC1 = "&.Cells(i 、1).Value、NumOfRec、adExecuteNoRecords' – Zac