I'm trying to update NUM_ID to 1 where NUM_ID is 4.
My table looks like this range A1:A6
NUM_ID 1 1 4 2 2
Excel returns error "No value given for one or more required parameters" on code below.
Sub Update()
Dim strNUM_ID As Double
Dim strSQL As String
Dim cnn As ADODB.Connection
strNUM_ID = 1
strSQL = "UPDATE [Sheet1$] " & _
"SET [NUM_ID] = strNUM_ID " & _
"WHERE [NUM_ID] = 4;"
Debug.Print strSQL
Set cnn = New ADODB.Connection
With cnn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source=C:\Temp" & _
"Test.xlsm;" & _
"Extended Properties=Excel 12.0;"
.Open
.Execute strSQL, DbFailOnError
End With
cnn.Close
Set cnn = Nothing
End Sub
Using Excel 2010
Change the following line(s)
strSQL = "UPDATE [Sheet1$] " & _
"SET [NUM_ID] = strNUM_ID " & _
"WHERE [NUM_ID] = 4;"
to
strSQL = "UPDATE [Sheet1$] " & _
"SET [NUM_ID] = " & strNUM_ID & " " & _
"WHERE [NUM_ID] = 4;"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.