Access使用代码刷新链接表
Private Sub c_connect_Click()
Err = 0
On Error Resume Next
Dim wrkODBC As Workspace
Dim conPubs As Connection
Dim mydb As Database, mytable As TableDef
Dim I As Integer, j As Integer
Dim connectstr As String
DoCmd.Hourglass True
DoCmd.SetWarnings False
Set mydb = DBEngine.Workspaces(0).Databases(0)
Dim passdb As String, ww As Integer
Dim f As Integer, g As Integer
passdb="pass"
connectstr = "ODBC;DSN=" & Me.dsn & ";"
connectstr = connectstr & "UID=" & Me.dbuser_id & ";"
connectstr = connectstr & "PWD=" & passdb & ";"
'connectstr = connectstr & "PWD=" & Me.dbpass_id & ";"
Set wrkODBC = CreateWorkspace("NewODBCWorkspace", "", "", dbUseODBC)
Set conPubs = wrkODBC.OpenConnection("sam_user", dbDriverNoPrompt, , connectstr)
If Err <> 0 Then GoTo dbuser_sam_err
On Error GoTo dbuser_conn_err
I = mydb.TableDefs.count 'tables count
For j = 0 To I - 1
Set mytable = mydb.TableDefs(j)
If mytable.Attributes = DB_ATTACHEDODBC Or mytable.Attributes = DB_ATTACHEDODBC + DB_ATTACHSAVEPWD Then
mytable.connect = connectstr
mytable.RefreshLink
End If
Next
On Error Resume Next
DoCmd.Hourglass False
MsgBox "数据表连接完成!", , "天鸣"
Err = 0
Exit Sub
dbuser_sam_err:
DoCmd.Hourglass False
MsgBox "数据库用户,口令错误,重新登录!", , "天鸣"
Err = 0
Exit Sub
dbuser_conn_err:
DoCmd.Hourglass False
MsgBox Error$(Err), 16, "天鸣"
Err = 0
Exit Sub
End Sub
(责任编辑:admin)
- ·用DAO或ADO正确访问Access 2000
- ·Access开发网络共享版技巧(多人同时操
- ·access中ADO与DAO格式的区别和写法【总
- ·access执行操作查询的几种方法对比
- ·Access中CurrentDb().Execute 和DoCmd.
- ·[源创技巧]在ACCESS中使用代码来自动创
- ·更新访问权限 (Jet) 数据库中的 40 多
- ·【实例】ADO代码计算余额法
- ·DAO实现的子窗体记录分页显示
- ·分别使用DAO和ADO连接外部数据库和Sql
- ·怎样判断一个表是否存在于数据库中? (D
- ·处理加了密码的MDB文件
- ·谈ADO访问不同数据库的差别
- ·DAO基础(4)
- ·DAO基础(3)
- ·DAO基础(2)