用链接表向导,会有提示输入密码,根据向导提示完成即可。当然也可以用代码来做。
strName:数据库名称;strPath:数据库路径;strPWD;数据库密码;
Public Function ReLink(ByVal strName As String, ByVal strPath As String, ByVal strPWD) As Boolean
Dim dbs As Database
Dim tdf As TableDef, i As Variant
On Error GoTo ErrorHandler
ReLink = False
Set dbs = CurrentDb
For Each i In Application.CurrentData.AllTables '历遍的有表
If DCount("*", "MSysObjects", "[Name]='" & i.Name & "' And [Type]=6") > 0 Then
'判断只有链接表才运行以下代码
strName = i.Name
Set tdf = dbs.TableDefs(strName)
tdf.Connect = "WD=" & strPWD & ";database=" & strPath
tdf.RefreshLink
End If
Next i
ReLink = True
Exit Function
ErrorHandler: ' 错误处理程序。
MsgBox "刷新失败!" & vbCr & vbCr & "失败原因 :" & vbCr & vbCr & _
"错误代码 : " & Err.Number & vbCr & _
"错误描述 : " & Err.Description, _
vbCritical
End Function
[此贴子已经被作者于2006-8-21 18:48:12编辑过]
|