2014年3月27日 星期四

Access 2007 VBA read data from CSV file

Reference:
http://stackoverflow.com/questions/11275356/vba-procedure-to-import-csv-file-into-access
http://msdn.microsoft.com/en-us/library/office/ff835958(v=office.15).aspx
http://www.access-programmers.co.uk/forums/showthread.php?t=57882
http://bytes.com/topic/access/answers/902423-how-delete-tables-using-vba-within-access-2007-database

Dim fDialog As Object
Dim rst As New ADODB.Recordset
For Each tbl In CurrentDb.TableDefs
     If InStr(tbl.Name, "tblImport") Then
         CurrentDb.TableDefs.Delete (tbl.Name)
     End If
Next tbl
myFileName = "c:\tmp\0327.csv"
DoCmd.TransferText TransferType:=acLinkDelim, TableName:="tblImport", FileName:=myFileName, HasFieldNames:=False
rst.Open "tblImport", CurrentProject.Connection, adOpenKeyset
'有 adOpenKeyset 才能正確取得 RecordCount
rst.MoveFirst
MsgBox rst.Fields(0)
MsgBox rst.RecordCount
rst.Close
Set rst = Nothing

沒有留言:

張貼留言