了解 Microsoft Access 安全性
时间:2007-12-23 来源:不详 作者:迈克DB
添加和删除组
添加组的过程与添加用户的过程类似。 Private Function AddGroup(ByVal strGroup As String, _ ByVal strPID As String) As Boolean Dim catDB As ADOX.Catalog On Error GoTo AddGroup_Err Set catDB = New ADOX.Catalog With catDB ' 在当前中打开 Catalog 对象。 .ActiveConnection = CurrentProject.Connection ' 创建新的组。 .Groups.Append strGroup, strPID End With ' 关闭 Catalog 对象。 Set catDB = Nothing AddGroup = True AddGroup_Err: Msgbox Err.Number & ":" & Err.Description AddGroup = False End Function 此过程首先实例化 Catalog 对象,然后打开一个到当前的连接。接下来,通过使用来自调用过程的参数,将新组追加到 Catalog 对象的 Groups 集合。 要删除现有组,可以使用以下过程: Private Function DeleteGroup(ByVal strGroup As String) As Boolean Dim catDB As ADOX.Catalog On Error GoTo DeleteGroup_Err Set catDB = New ADOX.Catalog With catDB ' 在当前中打开 Catalog 对象。 .ActiveConnection = CurrentProject.Connection ' 删除 strGroup。 .Groups.Delete strGroup End With ' 关闭 Catalog 对象。 Set catDB = Nothing DeleteGroup = True DeleteGroup_Err: Msgbox Err.Number & ":" & Err.Description DeleteGroup = False End Function 此过程与前面的过程类似,只是使用了 Catalog 对象的 Delete 方法删除了在 strGroup String 参数中指定的组。 下面我们来看看如何通过编程设置对对象的权限。通过编程设置权限
要对中的各种对象设置权限,可以使用 Group 或 User 对象的 SetPermissions 方法。在下面的过程中,我们首先撤消组的所有权限,然后再赋予组特定的权限。这样可以确保该组只具有我们指定的权限: Private Function SetGroupPermissions(ByVal strGroup As String, _ ByVal strTable As String, ByVal strObjectType As String, _ ByVal strAction As String, _ ByVal strRevokeEnum As String) As Boolean Dim catDB As ADOX.Catalog On Error GoTo SetGroupPermissions_Err Set catDB = New ADOX.Catalog With catDB ' 在当前中打开 Catalog 对象。 .ActiveConnection = CurrentProject.Connection ' 撤消组的所有权限。 .Groups(strGroup).SetPermissions tblTable, _ strObjectType, strAction, strRevokeEnum ' 赋予组特定的权限。 .Groups(strGroup).SetPermissions tblTable, _ strObjectType, strAction, _ adRightRead Or adRightInsert Or adRightUpdate End With ' 关闭 Catalog 对象。 Set catDB = Nothing SetGroupPermissions = True SetGroupPermissions_Err: Msgbox Err.Number & ":" & Err.Description SetGroupPermissions = False End Function 在当前中打开一个
上一篇:Access数据库开发技巧 下一篇:怎样可以从ACCESS中打印一个WORD文档
文章评论
共有位Admini5网友发表了评论 查看完整内容