我正在编写一个宏,它将从一个 Excel 工作簿运行并将其中一个 ListObjects 导出到我的访问文件中。
我现在有这个 VBA 代码:
Sub AccessImport()
' Create connection
Dim Path As String
Dim conn As Object
Dim connectstr As String
Dim recordset As Object
Dim strSQL As String
Path = "P:\CALIBRE-YSP Implementation\11 General\CDM Database"
Set conn = CreateObject("ADODB.Connection")
connectstr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Path & "\CDM_Database_DataOnly.mdb;"
strSQL = "SELECT * INTO DeliverablesLivesheet FROM [Excel 8.0;HDR=YES;DATABASE=P:\CALIBRE-YSP Implementation\11 General\CDM Database\CDMv2 - Development.xlsm].[DeliverablesImport];"
conn.Open connectstr
Set recordset = conn.Execute(strSQL)
recordset.Close
Set recordset = Nothing
conn.Close
Set conn = Nothing
End Sub
它应该从 Excel 中获取一个 ListObject,然后将数据传输到一个新的访问表,覆盖旧的访问表。
它在尝试执行 SQL 时抛出错误:
strSQL = "SELECT * INTO DeliverablesLivesheet FROM [Excel 8.0;HDR=YES;DATABASE=P:\CALIBRE-YSP Implementation\11 General\CDM Database\CDMv2 - Development.xlsm].[DeliverablesImport];"
所以我猜SQL有问题?
我似乎无法解决它
谢谢