Private Sub Form_Load()
relink
End Sub
Function relink()
Dim db As Database
Dim tbl As TableDef
Dim a As String
Dim b As String
Dim d As String
a = "sa" '数据库用户
b = "1" '数据库口令
d = "Materials" '数据库名称
Set db = CurrentDb
For Each tbl In db.TableDefs
If tbl.Attributes = 536870912 Then
tbl.Connect = "FILEDSN=MaterialsSource.dsn;UID=" & a _
& ";PWD=" & b & ";WSID=JBSERVER;DATABASE=" & d & ";Network=DBMSSOCN"
tbl.Attributes = AttachSavePWD
tbl.RefreshLink
End If
Next
End Function
这是在其他帖子上查到的代码修改后的代码,搞不懂(后面改成绝对路径时可以运行了,但我需要能用相对路径)
------解决思路----------------------
tbl.Connect = "FILEDSN=" & CurrentProject.Path & "\MaterialsSource.dsn;UID=" & a _
& ";PWD=" & b & ";WSID=JBSERVER;DATABASE=" & d & ";Network=DBMSSOCN"