this sub run in access import data excel file, "filename"
this connection string/open procedure pretty copied msdn references, there error.
when step through, receive "unrecognized database format" on oconn.open line.
filename spreadsheet, not database. how indicate this?
public sub import2(filename variant) dim wb object, ws object dim xl object set xl = createobject("excel.application") dim qs string dim valuestring string dim sconn string dim oconn object set oconn = createobject("adodb.connection") oconn.connectionstring = "provider=microsoft.ace.oledb.12.0; data source=filename; extended properties=excel 12.0 xml; hdr=yes" & ";" oconn.open filename 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) 'following lines may or may not correct. working on connection string 'valuestring = format(data1, "yyyy\/mm\/dd") 'qs = "insert maf (formdate) values (#" & valuestring & "#)" docmd.runsql (qs) 'currentdb.execute qs end sub
change data source=filename
data source=c:\test\db1.mdb
path of file
Comments
Post a Comment