Syntax error with INSERT INTO Access vba -
when run following code, receive syntax error insert statement. prior executing docmd step, locals window shows value of valuestring string value of "1/4/2016"
i assume error has string being entered date field, not sure how fix it.
formdate formatted date , data1 not declared, though shows in locals window date, #1/4/2016#
public sub import2(filename variant) dim wb object, ws object dim xl object set xl = createobject("excel.application") dim qs string dim valuestring string 'opens workbook, populates data1, etc. set wb = xl.workbooks.open(filename) set ws = wb.worksheets("for export") data1 = ws.cells(2, 1) data2 = ws.cells(2, 2) data3 = ws.cells(2, 3) valuestring = "(" & data1 & ")" qs = "insert maf (formdate) values & valuestring" docmd.runsql qs 'currentdb.execute qs
modify this:
data1 = ws.cells(2, 1) valuestring = format(data1, "yyyy\/mm\/dd") qs = "insert maf (formdate) values (#" & valuestring & "#)"
Comments
Post a Comment