sql - Trying to use VBA variable in Access UPDATE Statement -
so title says trying use vba variable within update statement. being used because want loop through each cell in range , subtract value worksheet value within table corresponding iterations cell reference. however, statement runs error saying "too many parentheses." however, odd me b/c pulled sql syntax directly out of access. guess missing something? post both versions of code:
code vba variables :
private sub updizzle() dim rcell range dim rrng range dim con new adodb.connection dim rs new adodb.recordset dim strconnection string dim quv long dim iid string set rrng = activeworkbook.sheets("sheet1").range("b2:b100") each rcell in rrng.cells if rcell <> "" , rcell.value <> 0 iid = rcell quv = rcell.offset(0,x).value strconnection = "provider=microsoft.ace.oledb.12.0;data source=c:\users\ashleysaurus\desktop" & "\" & "xyzmanu3.accdb" con.open strconnection rs.open "update stuff set stuff.quantity = quantity-" & quv & " (((stuff.[itemid])=" & iid & "));", con con.close end if next rcell end sub
code without variable:
strconnection = "provider=microsoft.ace.oledb.12.0;data source=c:\users\ashleysaurus\desktop" & "\" & "xyzmanu3.accdb" con.open strconnection rs.open "update stuff set stuff.quantity = quantity-1 (((stuff.[itemid])=thingamagig));", con con.close
as iid
string shouldn't
rs.open "update stuff set stuff.quantity = quantity-" & quv & " (((stuff.[itemid])='" & iid & "'));", con
(single quotes around iid)
Comments
Post a Comment