Chinaunix首页 | 论坛 | 博客
  • 博客访问: 19283934
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类: Mysql/postgreSQL

2008-05-30 09:56:16

以下为引用的内容:

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

阅读(397) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~