|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我是通过EXCEL操作ACCESS数据库,现在想把数据库1中的表二的数据复制或追加到数据库2的表二中,两张表的结构完全一样,请各位高手帮忙,谢谢了!
我找的代码只能在同一数据库内进行复制或备份
Public Sub BF()
Dim mydata As String
Dim myTable As String
Dim myCopyName As String
Dim SQL As String
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
mydata = ThisWorkbook.Path & "\1.mdb"
myTable = "表"
myCopyName = "新表"
Set cnn = New ADODB.Connection
With cnn
.Provider = "microsoft.jet.oledb.4.0"
.Open mydata
End With
On Error Resume Next
SQL = "drop table " & myCopyName
Set rs = cnn.Execute(SQL)
On Error GoTo 0
SQL = "select * into " & myCopyName & " from " & myTable
Set rs = cnn.Execute(SQL)
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
[ 本帖最后由 青见 于 2011-6-23 10:52 编辑 ] |
|