打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
VB 删除 ACCESS 数据库的密码

删除函数:

Public Sub RemoveDatabase_Password(ByVal strDBWithPassword As String, ByVal strPassword As String)
                       
On Error GoTo ErrorHandler
Dim objEngine As New JRO.JetEngine
Dim strBackupFile As String
Dim strDBWithOutPassword As String
Dim DBWithPwd As String, DBWithOutPwd As String

If Len(Dir(strDBWithPassword)) And Len(strPassword) <> 0 Then
    ' 是否备份
    If MsgBox("删除密码之前是否备份源数据库?", vbYesNo, "提示") = vbYes Then
        strBackupFile = "C:\Mybackup.mdb"
        If Len(Dir(strBackupFile)) Then Kill strBackupFile
        FileCopy strDBWithPassword, strBackupFile
    End If
   
    '建立临时文件
    strDBWithOutPassword = "c:\Temp40005.mdb"
    If Len(Dir(strDBWithOutPassword)) Then Kill strDBWithOutPassword '若临时文件存在,删除临时文件
    
    DBWithPwd = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
        & strDBWithPassword & ";" & "Jet OLEDB:Database Password=" & strPassword & ";"

    DBWithOutPwd = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
                  & strDBWithOutPassword & " ;Jet OLEDB:Engine Type=5;"

    DoEvents
   
    objEngine.CompactDatabase DBWithPwd, DBWithOutPwd
    Set objEngine = Nothing
   
    '删除有密码的数据库
    Kill strDBWithPassword
    '复制去除密码大数据
    FileCopy strDBWithOutPassword, strDBWithPassword
    Kill strDBWithOutPassword '删除临时数据库
   
    MsgBox "恭喜,密码已成功从数据中删除", vbInformation, "成功"
Else
   
    MsgBox "输入的数据库密码不正确!", vbCritical, "失败"

End If

Exit Sub
ErrorHandler:
  If Err.Number = -2147217843 Then
    MsgBox "密码无效请重试!", vbCritical, "密码错误"
  Else
    MsgBox "错误 # " & Err.Number & " : " & Err.Description & _
        " in RemoveDatabase_Password()", vbOKOnly, "提示"
  End If
End Sub

调用方法:

Call RemoveDatabase_Password(‘数据库路径', '数据库密码')

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
用C#连接Access数据库做登录界面
Excel各种密码解锁姿势(收藏备用)
VB实例教程之操作Access数据库
Excel VBA连接各种类型数据库-Excel、Access、mysql、sqlserver
c# 连接带有密码的ACCESS 2007数据库
《神奇的VBA》编程:查询Access数据库
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服