Ms access 每年将csv文件导入新数据库

Ms access 每年将csv文件导入新数据库,ms-access,vba,Ms Access,Vba,我应该在Access中创建一个数据库,稍后将传输到Oracle。每年我都要导入一个包含数百万行数据的csv文件,可以追溯到1985年。我相信Access无法保存所有这些数据,所以我想我应该有一个主数据库引用其他数据库 每年创建数据库需要什么代码 这就是我到目前为止所做的: DocLocate = InputBox("Input Document Location") & "\" StartYear = InputBox("Input Start Year") EndYear = Inpu

我应该在Access中创建一个数据库,稍后将传输到Oracle。每年我都要导入一个包含数百万行数据的csv文件,可以追溯到1985年。我相信Access无法保存所有这些数据,所以我想我应该有一个主数据库引用其他数据库

每年创建数据库需要什么代码

这就是我到目前为止所做的:

DocLocate = InputBox("Input Document Location") & "\"
StartYear = InputBox("Input Start Year")
EndYear = InputBox("Input End Year")
i = StartYear

strPath = DocLocate

strTable = strFile

strFile = "mar31_wts_" & i & ".csv"
Do Until i > EndYear
    strPathFile = strPath & strFile
    DoCmd.TransferText acImportDelim, acSpreadsheetTypeText, strFile, strPathFile, blnHasFieldNames
    i = i + 1
    strFile = "mar31_wts_" & i & ".csv"
Loop

有多种方法可以将csv数据导入Access数据库。使用
DoCmd.TransferText
方法,您将导入执行代码的应用程序的当前数据库

如果要导入到执行VBA代码的数据库之外的另一个数据库中,则必须创建另一个
应用程序
对象,并在其中打开目标数据库:

Dim app As Application
Dim strDBPath As String

' create the database
strDBPath = "<path_to_db>\db.accdb"
DAO.CreateDatabase(strDBPath, dbLangGeneral).Close

' open the database in a new Access Application
Set app = New Application
app.OpenCurrentDatabase strDBPath

' import the csv file into that database
app.DoCmd.TransferText acImportDelim, acSpreadsheetTypeText, strFile, strPathFile, blnHasFieldNames

' close the database and the Access application
app.Quit acQuitSaveNone

迭代的最佳方式是什么,以便每年创建一个新的数据库。我做了:“直到我>年底”还有,链接线的最佳放置位置在哪里?需要在导入数据之后,可能在最后,在
应用程序之后最好。在迭代中退出
?从年初到年末迭代的最佳方式是什么?我使用了:Do Until I>endyear如果你想为循环期间导入的每个文件创建链接,最好将创建链接的代码也放在循环中!创建循环有几种方法,最适合您的方法是
for
循环,如下所述:
DoCmd.TransferDatabase acLink, , strDBPath, acTable, strFile, strFile