deleting a user with DAO

  • Thread starter Thread starter Jesper Fjølner
  • Start date Start date
J

Jesper Fjølner

I'm trying to delete as user from a workgroup file using DAO.
Maybe someone has a snippet that does this.

I'm starting with something along the lines of:

Dim ws As Workspace
Dim usr As User
Set ws = DBEngine.CreateWorkspace("", "dbadmin", "dbadmin")

Now do I need to cycle all groups to delete the user from each one?
If I only use:
ws.users.delete(username) it doesn't seem to be enough.
Do I need to refresh all groups or can the users be deleted from as single
place and be gone from all groups?

Thanks.

Jesper
 
Good question. Try deleting the user, then refreshing the Users and
Groups collections of both workspaces (your admin one, and the
current/default one):

ws.users.refresh
ws.groups.refresh
dbengine(0).users.refresh
dbengine(0).groups.refresh

or maybe just:

currentdb

If this still "isn't enough", define what you mean by "isn't enough".
You haven't said what you actually mean by that. What happens to make
you think that it isn't enough?

HTH,
TC
 
If this still "isn't enough", define what you mean by "isn't enough".

Hi TC,

Thanks for your help.

I think I have it working now and have the functions neede to create some
custom add/delete functionality to the database.
Now I just need a 'change password' function.

I'm listing users in the system with this:

Function fListUsersInSystem() As String
Dim ws As Workspace
Dim i As Integer
Dim sUrs As String
Set ws = DBEngine.Workspaces(0)
For i = 0 To ws.Users.Count - 1
sUrs = sUrs & ws.Users(i).Name & ";"
End If
Next i
fListUsersInSystem = sUrs
End Function

And I'm deleting a user with:

Sub sDeleteUser(strUsername As String)
Dim ws As Workspace
Dim usr As User
Set ws = DBEngine.CreateWorkspace("wsdbadmin", "dbadmin", "dbadmin")
ws.Users.Delete strUsername
ws.Users.Refresh
Set usr = Nothing
Set ws = Nothing
End Sub

All seems to work now. Only thing that tricked was when I forgot to refresh
with ws.users.refresh

Many thanks for the help so far!



Jesper Fjølner
 
No problems, glad it is working.

However, be aware that there is no benefit in doing this:

ws.users.refresh ' <<<
set ws = nothing

The only reason to refresh the ws Users or Groups collections, would be
if you planned to continue using those collections in the code that
follows after. But you do not continue using those collections, you
just discard the workspace reference. So you could actually remove the
ws.users.refresh, and that should make no difference at all.

Cheers,
TC
 
However, be aware that there is no benefit in doing this:
ws.users.refresh ' <<<
set ws = nothing

The only reason to refresh the ws Users or Groups collections, would be
if you planned to continue using those collections in the code that
follows after. But you do not continue using those collections, you
just discard the workspace reference. So you could actually remove the
ws.users.refresh, and that should make no difference at all.

That's noted. Thanks again :-)


Jesper Fjølner
 
Back
Top