标题: 请教用代码一次连接SQL多个表要如何写 [打印本页] 作者: huangjingfeng88 时间: 2010-10-23 18:52 标题: 请教用代码一次连接SQL多个表要如何写 Function LinkToPubsAuthorsDSNLess()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim strConnect As String RunCode
Dim strServer As String
Dim strDatabase As String
Dim strUID As String
Dim strPWD As String
strServer = "IP地址"
strDatabase = "数据库名称"
strUID = "用户名"
strPWD = "数据库密码"
strConnect = "ODBC;DRIVER={SQL Server}" _
& ";SERVER=" & strServer _
& ";DATABASE=" & strDatabase _
& ";UID=" & strUID _
& "WD=" & strPWD & ";"
Set db = CurrentDb()
Set tdf = db.CreateTableDef("要创建的链接表名称")
tdf.SourceTableName = "目标表名称"
tdf.Connect = strConnect
db.TableDefs.Append tdf
db.TableDefs.Refresh
Set tdf = Nothing
Set db = Nothing
End Function