vba - Insert Into Syntax Issues -
i think may have insert sql table issue resolved. keep hitting syntax error issue , highlighting whole qdf.sql= "insert into..... portion. trying troubleshoot did wrong. experts out there can spot issue is?
public function update() dim cdb dao.database, qdf dao.querydef dim rs recordset dim err dao.error const destinationtablename = "ac_cddata" const connectionstring = _ "odbc;" & _ "driver={sql server native client 10.0};" & _ "server=gaalpsvr031b\p003,49503;" & _ "database=db;" & _ "uid=id;" & _ "pwd=pw;" set cdb = currentdb set qdf = cdb.createquerydef("") set rs = currentdb.openrecordset("cddata", dbopentable) qdf.connect = connectionstring while not rs.eof qdf.sql = "insert ac_cddata_1(employeeid, employeename, region, district, function1, gender, eeoc, division, center, meetingreadinesslevel, managerreadinesslevel, employeefeedback, developmentforemployee1, developmentforemployee2, developmentforemployee3, developmentforemployee4, developmentforemployee5, justification, changed, jobgroupcode, jobdesc, jobgroup) " & _ "values (" & _ "'" & rs.employeeid & "', " & _ "'" & rs.employeename & "', " & _ "'" & rs.region & "', " & _ "'" & rs.district & "', " & _ "'" & rs.function1 & "', " & _ "'" & rs.gender & "', " & _ "'" & rs.eeoc & "', " & _ "'" & rs.division & "', " & _ "'" & rs.center & "', " & _ "'" & rs.meetingreadinesslevel & "', " & _ "'" & rs.managerreadinesslevel & "', " & _ "'" & rs.employeefeedback & "', " & _ "'" & rs.developmentforemployee1 & "', " & _ "'" & rs.developmentforemployee2 & "', " & _ "'" & rs.developmentforemployee3 & "', " & _ "'" & rs.developmentforemployee4 & "', " & _ "'" & rs.developmentforemployee5 & "', " & _ "'" & rs.justification & "', " & _ "'" & rs.changed & "', " & _ "'" & rs.jobgroupcode & "', " & _ "'" & rs.jobdesc & "', " & _ "'" & rs.jobgroup"')" qdf.returnsrecords = false on error goto update_qdferror qdf.execute dbfailonerror on error goto 0 rs.movenext loop rs.close set qdf = nothing set cdb = nothing set rs = nothing exit function update_qdferror: each err in dao.errors msgbox err.description, vbcritical, "error " & err.number next end function
you have error when building string ...
"'" & rs.jobgroup"')"
change ...
"'" & rs.jobgroup & "')"
it's easier spot problems using string variable hold sql statement.
dim strinsert string strinsert = "insert ..."
then can inspect string ...
debug.print strinsert
and assign string querydef ...
qdf.sql = strinsert
Comments
Post a Comment