When you use an MDB to SEVER2000 a link to SQL, you sometimes need to refresh the linked table, which can be achieved by following code
The solution of this topic refer to the code of Netizen Cwang, and get the enthusiastic help of Microsoft engineer Billy Yao, thanks here!
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 = "abc"'数据库口令
d = "abcde"'数据库名称
Set db = CurrentDb
For Each tbl In db.TableDefs
If tbl.Attributes = 536870912 Then
tbl.Connect = "FILEDSN=d:\demo\steel.dsn;UID=" & a & ";PWD=" & b & ";WSID=;DATABASE=" & d & ";Network=DBMSSOCN"
'
tbl.Attributes = dbAttachSavePWD
tbl.RefreshLink
End If
Next
End Function
Enclosed is the answer to the Microsoft engineer Billy Yao:
According to your description, my answer to your question is as follows:
1. dsn=gnts gnts is the file name of the system DSN.
2. UID is the username, and its value is determined by the value of variable A. PWD is a password, and its value is determined by the value of the variable B.
3. Wsid refers to the workstation's ID number (Workstation ID). The value of the variable d represents the name of the database. NETWORK=DBMSSOCN refers to the network library (network library) used by TCP/IP. Getting Started with programming (http://bianceng.cn)
For more information about ODBC DSN Connection string, you can see the following articles:
Http://www.able-consulting.com/MDAC/ADO/Connection/ODBC_DSN.htm
http://support.microsoft.com/default.aspx?scid=kb; en-us;260249