使用代码刷新链接表

时间:2008-10-07 12:05:18  来源:第二电脑网上收集  作者:

  第二电脑网导读:p; 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 = DBEngin...
  正文:

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


"使用代码刷新链接表"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/ASP/2008-10-07/2975.html


关键字:

关于《使用代码刷新链接表》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td