一。首先在模块中添加如下代码。
对象类型是DAO/ADO ============ 对 DAO 定义 dim wkData as dao.workspace Dim dbData as dao.Database ============ 对ADO定义 dim cnn as new connection
二。在模块中创建如下过程
Option Explicit '* 使用DAO打开带密码数据库 Sub OpendatabaseWithPassword(DB As Object, strDatabase As String, strPass As String) Set DB = DBEngine.OpenDatabase(App.Path & "\" & strDatabase, False, False, ";pwd=" & strPass) End Sub '* 使用ADO打开带密码数据库 Sub OpenConnectionWithPassword(DB As Object, strProvider, strDataSource As String, strPassWord As String) DB.Open _ strProvider & _ strDataSource & _ strPassWord End Sub '* 使用DAO修改数据库密码 Sub ChangeDBPassword_DAO(DB As Object, strDatabase As String, strOldPass As String, strNewPass As String) Set DB = DBEngine.OpenDatabase(App.Path & "\" & strDatabase, True, False, ";pwd=" & strOldPass) DB.NewPassword strOldPass, strNewPass DB.Close End Sub '* 使用DAO修改用户密码 Sub ChangeUserPassword_DAO(DB As Object, strOldPass As String, strNewPass As String) DBEngine.SystemDB = "c:\win98\system\system.mdw" Set DB = DBEngine.CreateWorkspace("", "Admin", strOldPass) DB.Users("Admin").NewPassword strOldPass, strNewPass DB.Close End Sub '* 使用ADO修改用户密码 '* Assumes that the Admin user doesn't currently have a password set '* Provider=Microsoft.Jet.OLEDB.4.0; Sub ChangeUserPassword_ADO(DB As Object, strProvider, strDataSource As String, strSystem As String, strOldPassword As String, strNewPassword As String) DB.ActiveConnection = _ strProvider & _ strDataSource & _ strSystem DB.Users("Admin").ChangePassword strOldPassword, strNewPassword Set DB = Nothing End Sub '* 使用DAO添加新用户 组 密码 Sub CreateUserGroup_DAO(DB As Object, User As Object, NewUser As String, strPID As String, strPassWord As String, wrkPass As String) DBEngine.SystemDB = "c:\win98\system\system.mdw" Set DB = DBEngine.CreateWorkspace("", "Admin", wrkPass) Set User = DB.CreateUser(NewUser, strPID, strPassWord) DB.Users.Append User DB.Close End Sub '* 添加新用户到组 -tmtony Sub AddUserToGroup(DB As Object, strPass As String, strNewUser As String, strNewGroup) DBEngine.SystemDB = "c:\win98\system\system.mdw" Set DB = DBEngine.CreateWorkspace("", "Admin", strPass) DB.Users(strNewUser).Groups.Append _ DB.Users(strNewUser).CreateGroup(strNewGroup) DB.Close End Sub
三。使用方法 OpenDatabaseWithPassWord(dbData, "Test.mdb", "vbcode") OpenConnectionWithPassWord(cnn,"Provider=Microsoft.Jet.OLEDB.4.0;","Data Source=" + app.path + "\"+ "Test.mdb","vbcode")
原作者:Chris Cabayao
原文:http://www.vbcode.com/asp/showsn.asp?theID=1614
翻译:tmtony(王宇虹) http://www.office-cn.net tmtony@21cn.com
|