程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Access數據庫 >> 關於Access數據庫 >> 使用代碼刷新鏈接表

使用代碼刷新鏈接表

編輯:關於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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved