2014-09-22 83 views
0

是否可以在Excel電子表格和Access數據庫表之間建立內部聯接? 我嘗試了很多方法來使這可能,但沒有成功。使用Access記錄集內部加入Excel記錄集

這是我的Visual Basic 6代碼:

Dim DbTemp As Database 
Dim ExcelDB As Database 
DIm xlsRs As Recordset 

Set DbTemp = OpenDatabase(App.Path + "\mydb.mdb") 
Set ExcelDB = OpenDatabase(App.path + "\QueryExcelDATA.xls", False, True, "Excel 8.0;") 
Set xlsRS = ExcelDB.OpenRecordset(query, dbOpenDynaset) ' query is a sql query I used to get some other results 

Do Until xlsRs.EOF 
     Workspaces(0).BeginTrans 
      sql = "INSERT INTO Presenze(Enterprise, Emp_ID, mYear, mMonth, mDay, WorkHours) " _ 
       & " SELECT Presenze.Emp_ID, '"+xlsRs("Entps")+"', '" + xlsRs("Yr") + "', '" + " _ 
       & " xlsRs("Mnth") + "', '" + xlsRs("Dy") + "', '" + xlsRs("WH") + `"' " _ 
       & " FROM [ExcelDATA$] INNER JOIN Presenze On [ExcelDATA$].[CardID] = Presenze.CardID" 
      DbTemp.Execute sql 
     Workspaces(0).CommitTrans 
     xlsRS.MoveNext 
Loop 

我想從[ExcelData $]電子表格中的數據,並把它們插入到訪問表「Presenze」 誰能幫助我?

回答

2

唯一現實的方法是在訪問數據庫中創建一個導入表,並將數據從Excel複製到其中,然後加入到此表中。這樣,每次Excel中的數據發生更改時,都不必重新創建連接。

+0

DoCmd.TransferSpreadsheet – 2014-09-22 19:10:00