| 网站首页 | 新闻 | 新书 | 专家 | 技巧 | 源码作品 | 工具/资源 | 商城 | 风采 | 留言 | 论坛 | 网址 | 承接 | 
您现在的位置: Access/Office中国 >> 技巧 >> Access >> 模块类函数VBA >> 文章正文 用户登录 新用户注册
如何用VBA更改数据库密码         ★★★
如何用VBA更改数据库密码
作者:未知 文章来源:gab2001uk 点击数: 本日:{$DayHits} 更新时间:2005-2-5 12:16:34


使用DAO方式改变密码

Private Sub cmdChangeDAO_Click()
    Dim strNewPassword As String
    
    'Check if a database is open
    If fDC Then 'using data control
        'Get new password
        strNewPassword = InputBox("Please type in new password. Leave blank to remove password protection")
        'Change password
        Data1.Database.NewPassword strPassword, strNewPassword
    Else
        If strSource = "" Then
            MsgBox "No current database open"
        Else
            'Get new password
            strNewPassword = InputBox("Please type in new password. Leave blank to remove password protection")
            'Change password
            db.NewPassword strPassword, strNewPassword
        End If
    End If
    'Update variable
    strPassword = strNewPassword
    WriteCaptions fDAO
End Sub

使用ADO方式改变密码

Private Sub cmdChangeADO_Click()
    Dim strNewPassword As String
    Dim strsql As String
    
    If fDC Then 'using data control
        'cannot change password from ADODC
        MsgBox "You have opened the database with ADODC data control. This control is not capable of changing the database password." & vbCrLf & "Use ADO Code connection string to achieve this."
    Else
        'Check if a database is open
        If strSource = "" Then
            MsgBox "No current database open"
        Else
            'Get new password
            strNewPassword = InputBox("Please type in new password. Leave blank to remove password protection")
            'Change password
            If strNewPassword = "" Then 'Remove password
                strsql = "ALTER Database Password `` " & strPassword
            Else
                If strPassword = "" Then 'no current password
                     strsql = "ALTER Database Password " & strNewPassword & " ``"
                Else 'straight forward change
                    strsql = "ALTER Database Password " & strNewPassword & " " & strPassword
                End If
            End If
            cnn.Execute strsql
        End If
    End If
    'Update variable
    strPassword = strNewPassword
    WriteCaptions fDAO
End Sub

 

文章录入:tm    责任编辑:tmtony 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    专 题 栏 目
    最 新 热 门
    最 新 推 荐
    相 关 文 章
    再提数据库正规化之数据
    数据库设计注意事项
    压缩、修复指定的数据库
    将Access数据库移植到SQ
    Access键盘快捷键大全
    模块的使用技巧
    数据库设计的技巧
    VBA自动安装和删除字体的
    Access数据库开发技巧
    Access数据库开发技巧
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)