sql - VBScript - Syntax Error in FROM Clause -
so i'd preface saying have little experience vbs. anyway, i'm trying write script want calculate year number of project (but leave blank under circumstances) database storing several projects.
there error i'm receiving is: error 800a0c3b – syntax error in clause. line 26 char 1 source: dao.database , can't quite figure out how fix it.
option explicit 'line 1 'declare variables dim rs1 dim rs2 dim year '5 dim yearno dim oaccess dim oshell dim dblocation dim currentdb '10 dim sql dim program_year dim construction_year dim ofso set ofso = createobject("scripting.filesystemobject") '15 set oshell = wscript.createobject("wscript.shell") dblocation = "[drive]\folder\folder\file.accdb" set oaccess = createobject("access.application") '20 oaccess.opencurrentdatabase(dblocation) 'sql = "select * [expenditures] in '" & dblocation & "' " '25 oaccess.currentdb.execute("select * [expenditures] in '" & dblocation & "'""") '26 set rs1 = currentdb.openrecordset(oaccess) 'move first record '30 rs1.movefirst 'copy recordset set rs2 = rs1.clone rs2.bookmark = rs1.bookmark rs2.movenext '35 while not rs2.eof rs2.edit '1. check if construction year before program year '40 if me.construction_year < me.program_year 'a) if year comes before program year, leave yearno blank if me.year < me.program_year me.yearno = "" '45 'b) if year program year or greater program year, fill in yearno elseif me.year > me.program_year or me.year = me.program_year if rs1.year < rs2.year , trim(rs1.gwp) = trim(rs2.gwp) rs2.yearno = rs2.year - rs1.year + rs1.yearno end if '50 end if '2. check if program year before construction year elseif me.program_year < me.construction_year '55 'a) if year comes before construction year, leave yearno blank if me.year < me.construction_year me.yearno ="" 'b) if year construction year or greater construction year, fill in yearno elseif me.year > me.construction_year or me.year = me.construction_year '60 if rs1.year < rs2.year , trim(rs1.gwp) = trim(rs2.gwp) rs2.yearno = rs2.year - rs1.year + rs1.yearno end if end if '3. check if program year , construction year same '65 elseif me.programyear = me.construction_year 'a) if year comes before program year, leave yearno blank if me.year < me.program_year me.yearno = "" 'b) otherwise fill in yearno '70 elseif rs1.year < rs2.year , trim(rs1.gwp) = trim(rs2.gwp) rs2.yearno = rs2.year - rs1.year + rs1.yearno end if end if '80 'end if 'update , move next rs2.update rs1.movenext '85 rs2.movenext loop 'close recordsets , set nothing rs2.close '90 rs1.close set rs1 = nothing set rs2 = nothing '95 oshell.popup "update complete!",2, "",0 oaccess.quit set oaccess = nothing wscript.quit
any assistance - , obvious problems in code - gratefully appreciated.
edit: forgot add database based in access.
sql? looks access. code old vbscript. may help:
' cursortypeenum values const adopenforwardonly = 0 const adopenkeyset = 1 const adopendynamic = 2 const adopenstatic = 3 ' locktypeenum values const adlockreadonly = 1 const adlockpessimistic = 2 const adlockoptimistic = 3 const adlockbatchoptimistic = 4 ' commandtypeenum values const adcmdunknown = &h0008 const adcmdtext = &h0001 const adcmdtable = &h0002 const adcmdstoredproc = &h0004 dim connection, rs, item, svcopsra(1), datafile, n, fs set fs = createobject("scripting.filesystemobject") dim currentpath, currentfolder set currentpath = fs.getfolder(".") currentfolder = currentpath.path set currentpath = nothing set connection = createobject("adodb.connection") connection.connectiontimeout = 30 connection.commandtimeout = 80 datafile = currentfolder & "\deploy.mdb" connection.open "driver={microsoft access driver (*.mdb)};dbq=" & datafile & ";defaultdir=;uid=;pwd=;" set rs = createobject("adodb.recordset") rs.open "select service, state svcops status", connection, adopenforwardonly, adlockoptimistic while not rs.eof n = 0 each item in rs.fields svcopsra(n) = item.value ' ... populating array values n = n + 1 next svcops svcopsra(0), svcopsra(1) ' ... call sub/function , pass 2 fields parameters rs.movenext wend rs.close connection.close set rs = nothing set connection = nothing set fs = nothing
the svcops
sub looks like:
sub svcops(service,state) ' ... takes 2 parameters ' ... end sub
also, if plan update recordset, use adopendynamic
instead of adopenforwardonly
;)
here's documentation on record lock , enum types: msdn - recordset object basics
Comments
Post a Comment