access如何通过代码实现在两个ODBC链接的SQLserver数据库中切换?在线等!!!
发布网友
发布时间:2022-04-11 15:18
我来回答
共1个回答
热心网友
时间:2022-04-11 16:47
这是VB的看给你什么启发:
Public Sub CreateSQLlinkTable(ByVal SQLServerName As String, ByVal Database As String, ByVal SQLTable As String, ByVal accTable As String, Optional ByVal SQLID As String = "SA", Optional ByVal SQLPASS As String = "")
'建链接表 SQLServerName为SQL服务器名称可以为IP地址,Database为数据库名称,SQLTable为SQL被连接的源表,accTable要新建的连接表名称,SQLID为SQL服务器ID默认为“SA”,SQLPASS为数据库密码默认为空
'调用方法如: call CreateSQLlinkTable2("192.168.1.200","UfNote_001_2009","Person","c123","sa","")
'调用参数全部要加双引号
Dim db As Database
Dim tdef As TableDef
Set db = CurrentDb()
Set tdef = db.CreateTableDef(accTable)
tdef.Connect = "ODBC;Driver=SQL Server;server=" & SQLServerName & ";UID=" & SQLID & ";PWD=" & SQLPASS & ";DATABASE=" & Database
tdef.SourceTableName = SQLTable
db.TableDefs.Append tdef
End Sub