background:
i receive daily sales files import access automatically. saved specific folder consistent naming convention. don't review these files everyday , make import process push button procedure. there other files in folder don't need, can't import entire file.
file naming convention: daily.sales.20160611
(the 20160611 year - 2016, month - june, , day 11th)
help needed:
i can import files, can't figure out how specify files begin "daily.sales". below code have can import without specifying. assumption has path or strfile, none of variations i've tried has worked.
it nice if code check if file has been uploaded before uploading it, however, if have delete table after each use , re-upload still easier.
dim strfile string 'filename dim strfilelist() string 'file array dim intfile integer 'file number dim filename string dim path string docmd.setwarnings false path = "c:\desktop\test\" dim objxl object dim wb object set objxl = createobject("excel.application") strfile = dir(path & "*.xls") while strfile <> "" set wb = objxl.workbooks.open(path & strfile) if wb.sheets(1).range("a1") <> "no data" , wb.sheets(1).range("a1") <> "" 'add files list intfile = intfile + 1 redim preserve strfilelist(1 intfile) strfilelist(intfile) = strfile end if strfile = dir() debug.print strfilelist(intfile) wb.close false set wb = nothing wend 'see if files found if intfile = 0 msgbox "no files found" exit sub end if 'cycle through list of files intfile = 1 ubound(strfilelist) filename = path & strfilelist(intfile) docmd.transferspreadsheet acimport, acspreadsheettypeexcel8, "stage", filename, false call format_staging_table call copy_from_stage_to_master call clear_staging_table next intfile docmd.setwarnings true
you can ignore call pieces, format data once in...
thanks or advice might able provide!
ok, answered question 1 minute ago. think should take @ link.
http://www.accessmvp.com/kdsnell/excel_import.htm#impallwktsseptbl
just modify suit needs... basically...change path , folder match file name...
Comments
Post a Comment