When using the MDB and SQL SEVER2000 link, sometimes need to refresh the linked table, through the following code to achieve the goal, the solution of this topic reference the user Cwang code, and get Microsoft engineer Billy Yao's enthusiastic help, 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 ' database user
b = ABC ' Database password
d = ABCDE ' database name
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=;D atabase= & 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. Gnts in Dsn=gnts is the file name of the System DSN.
2. The UID is the user name, and its value is determined by the value of the 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.
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