trying import data excel sheet , append access table. reads first value , appends it, second value not interpreted data, reason.
i assume format issue data4 variable, or way called in qs line. help?
public sub import2(filename variant) dim wb object, ws object dim xl object set xl = createobject("excel.application") dim qs string dim oconn object set oconn = createobject("adodb.connection") oconn.connectionstring = "provider=microsoft.ace.oledb.12.0; data source=c:\users\robert\desktop\testmaf.xlsm; extended properties=excel 12.0 xml; hdr=no" & ";" 'open workbook specified in previous procedure , import data specified cells 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) data4 = ws.cells(2, 4) 'continues ...data62 = ws.cells(2 , 62) 'the following commented code works, entering date formdate field on maf table 'qs = "insert maf (formdate) values (#" & data1 & "#)" 'however, when expanded include second field (below)it not enter value table. 'the locals window shows qs=...values(#1/4/2010#,postflight) want append 'but when qs executed, prompted, "enter parameter value postflight" qs = "insert maf (formdate,sn) values (#" & data1 & "#," & data4 & ")" docmd.runsql (qs) end sub
add quotes before , after text value "postflight" (which value contained in data4
variable) ...
qs = "insert maf (formdate,sn) values (#" & data1 & "#,'" & data4 & "')" ^ ^
you can make trouble-shooting easier if use variable hold insert
statement ...
dim strinsert string strinsert = "insert maf (formdate,sn) values (#" & data1 & "#,'" & data4 & "')" debug.print strinsert '<- view in immediate window; ctrl+g take there currentdb.execute strinsert, dbfailonerror
but quote issues less of pain if switch parameter query insert
or if use dao.recordset.addnew
add row maf
table.
here recordset
example (untested) ...
dim db dao.database dim rs dao.recordset set db = currentdb set rs = db.openrecordset("maf", dbappendonly) rs .addnew !formatdate.value = data1 !sn.value = data4 .update .close end
Comments
Post a Comment