确认表格和目标数据库已打开并且可用。
使用TransferDatabase方法进行转移,此方法比TransferSpreadsheet方法更稳定。
示例代码:
Dim SourceDb As Database
Dim DestinationDb As Database
Set SourceDb = DAO.OpenDatabase("C:\Folder\SourceDatabase.accdb")
Set DestinationDb = DAO.OpenDatabase("C:\Folder\DestinationDatabase.accdb")
DoCmd.TransferDatabase acExport, "Microsoft Access", SourceDb.Name, acTable, "SourceTableName", "DestinationTableName", True
SourceDb.Close
DestinationDb.Close
说明:此代码将源表(SourceTableName)从源数据库(SourceDatabase.accdb)转移到目标数据库(DestinationDatabase.accdb)中的目标表(DestinationTableName)。
如果仍然遇到问题,请考虑筛选出需要的数据并使用Recordset将其复制到目标表中。
示例代码:
Dim rstSource As DAO.Recordset
Dim rstDestination As DAO.Recordset
Set rstSource = CurrentDb.OpenRecordset("SELECT * FROM SourceTableName")
Set rstDestination = CurrentDb.OpenRecordset("SELECT * FROM DestinationTableName")
rstSource.MoveFirst
Do Until rstSource.EOF
rstDestination.AddNew
rstDestination!Field1 = rstSource!Field1
rstDestination!Field2 = rstSource!Field2
rstDestination.Update
rstSource.MoveNext
Loop
rstSource.Close
rstDestination.Close
说明:此代码将源表(SourceTableName)中的数据复制到目标表(DestinationTableName)中。请根据需要更改字段名称和数量。