1.先在Access中建个临时表Temp_tableName,字段tableName,Temp_tableName表里面先保存好需要从SQLServer上导入的表名称。
2.然后新建个窗体,在窗体上放个导入按钮,在导入按钮的单击事件中写如下代码
On Error GoTo Error_Handler
Dim rst As Object
DoCmd.Hourglass True
Set rst = CurrentProject.Connection.Execute("select tableName from Temp_TableName")
Do While Not rst.EOF
DoCmd.TransferDatabase acImport, "ODBC", "ODBC;DRIVER=SQL Server;SERVER=SQLServerIP地址;UID=SQLServer账号;PWD=SQLServer密码;DATABASE=SQLServer库名称;", acTable, rst![tableName], rst![tableName], False
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Exithere:
DoCmd.Hourglass False
Exit Sub
ErrorHandler:
MsgBox Err.Description, vbInformation, "提示"
Resume Exithere