使用下面的代码我设置链接表参数,我设置Usr
和Pws
,但每次程序启动时我使用链接表我收到此错误:
然后
现在我必须取消标记可信连接并再次输入Usr
和Pws
。
造成这种情况的原因是什么?
Public Function SetLinkedTablesTruck()
Dim db As DAO.Database
Dim tdf As TableDef
On Error GoTo ErrorHandler
Set db = CurrentDb
' Loop Table Defs
For Each tdf In db.TableDefs
If tdf.Name = "TruckOUT" Then
MsgBox tdf.Connect
tdf.Connect = "ODBC;DRIVER=SQL Server;SERVER=MYITSRV;DATABASE=dbItalianDb;TABLE=dbo.truckView;UID=UserView;PWD=UserView"
tdf.RefreshLink
db.TableDefs.Refresh
End If
Next
Set tdf = Nothing
Set db = Nothing
MsgBox "Tables Re-Linked"
ExitHandler:
Exit Function
ErrorHandler:
MsgBox "Error in SetLinkedTables : " & err.Description
Resume ExitHandler
End Function
答案 0 :(得分:-1)
您通常不包括表名,因此:
tdf.Connect = "ODBC;DRIVER=SQL Server;SERVER=MYITSRV;DATABASE=dbItalianDb;UID=UserView;PWD=UserView"