我正在重写数据库代码,以导入到拆分数据库的新后端,当我运行代码时,它将运行。但没有任何内容显示为新导入。我想知道我的代码中缺少什么吗?运行正常,我完全没有收到任何错误,但是当我运行以下功能时,没有导入任何excel工作表。任何更简单的方法也将很棒。最后,一旦创建了表,我希望将导入链接回前端数据库。
Private Function ImportBackend()
Dim blnHasFieldNames As Boolean, blnEXCEL As Boolean, blnReadOnly As Boolean
Dim lngCount As Long
Dim objExcel As Object, objWorkbook As Object
Dim colWorksheets As Collection
Dim strPathFile As String
Dim strPassword As String
Dim db As DAO.Database
Set db = DBEngine.Workspaces(0).OpenDatabase ("C:\Users\albroady\Documents\Database\MasterDataCommit1_2018-12-18_be.accdb")
' Establish an EXCEL application object
On Error Resume Next
Set objExcel = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
'Set objExcel = CreateObject("Excel.Application")
'blnEXCEL = True
End If
Err.Clear
On Error GoTo 0
' Change this next line to True if the first row in EXCEL worksheet
' has field names
blnHasFieldNames = True
' Replace C:\Filename.xls with the actual path and filename
strPathFile = "C:\Users\albroady\Documents\Master\Green.xlsx"
' Replace passwordtext with the real password;
'if there is no password, replace it with vbNullString constant
' (e.g., strPassword = vbNullString)
strPassword = "vbNullString"
blnReadOnly = True ' open EXCEL file in read-only mode
' Open the EXCEL file and read the worksheet names into a collection
Set colWorksheets = New Collection
Set objWorkbook = objExcel.Workbooks.Open(strPathFile, , blnReadOnly, , _
strPassword)
For lngCount = 1 To objWorkbook.Worksheets.Count
colWorksheets.Add objWorkbook.Worksheets(lngCount).Name
Next lngCount
' Close the EXCEL file without saving the file, and clean up the EXCEL objects
objWorkbook.Close False
Set objWorkbook = Nothing
If blnEXCEL = True Then objExcel.Quit
Set objExcel = Nothing
'Import the data from each worksheet into a separate table
For lngCount = colWorksheets.Count To 1 Step -1
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
"tbl_Update" & colWorksheets(lngCount), strPathFile, blnHasFieldNames, _
colWorksheets(lngCount) & "$"
Next lngCount
' Delete the collection
Set colWorksheets = Nothing
Set db = Nothing
' Uncomment out the next code step if you want to delete the
' EXCEL file after it's been imported
' Kill strPathFile
答案 0 :(得分:0)
我发现您实际上可以在“设计”视图中修改查询的属性,并将目标从“当前”更改为后端数据库的路径