Home > Archive > Delphi > May 2004 > Adding a group to an existing user in a msAccess workgroup using
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Adding a group to an existing user in a msAccess workgroup using
|
|
|
| Hallo all,
I have a delphi application that uses msAccess and DAO to connect to it.
I have created a procedure that creates a new user using DAO:
var dWorkspace : DAOWorkspace;
var dUser : DAOUser;
Begin
dWorkspace := JetEngine.Workspaces.Item[0] ;
dUser := dWorkspace.CreateUser(userName,userName,userName);
dWorkspace.Users.Append (dUser);
dUser.Free;
dWorkspace.Free;
JetEngine.FreeLocks;
end;
This works fine.
Then I need to make a procedure that will add an existing group to that
user.
I have made the following but it doesnt work (returns the error:
"EDAOError ;DAODynaCollection.Append failed" at the line:
groups.Append (dGroup); )
var dWorkspace : DAOWorkspace;
var dUser : DAOUser;
var groupname : string;
Begin
groupname := 'existinggroupname';
dWorkspace := JetEngine.Workspaces.Item[0] ;
dGroup := dWorkspace.Groups[groupname];
with dWorkspace.Users[username] do begin
groups.Append (dGroup);
Free;
end;
dGroup.Free;
dWorkspace.Free;
JetEngine.FreeLocks;
end;
Has anyone any ideas of how you add a group to a user using DAO?
Thanks
Koyan
| |
| Corey Lawson 2004-05-13, 10:31 pm |
| After you do all those dWorkspace.*.Append, try to do a dWorkspace.*.Refresh
At least, that is what I've had to do when writing
ASP/VBA/VBScript-based stuff like you have. Sure, the examples in the
Access books I have don't have this, but I found it was necessary to get
the changes actually "committed", as it were.
I've inlined changes below in your code.
Koyan wrote:
> Hallo all,
> I have a delphi application that uses msAccess and DAO to connect to it.
>
> I have created a procedure that creates a new user using DAO:
>
> var dWorkspace : DAOWorkspace;
> var dUser : DAOUser;
> Begin
> dWorkspace := JetEngine.Workspaces.Item[0] ;
> dUser := dWorkspace.CreateUser(userName,userName,userName);
> dWorkspace.Users.Append (dUser);
dWorkspace.Users.Refresh 'refresh the collection.
> dUser.Free;
> dWorkspace.Free;
> JetEngine.FreeLocks;
> end;
>
>
> This works fine.
>
> Then I need to make a procedure that will add an existing group to that
> user.
> I have made the following but it doesnt work (returns the error:
> "EDAOError ;DAODynaCollection.Append failed" at the line:
> groups.Append (dGroup); )
>
> var dWorkspace : DAOWorkspace;
> var dUser : DAOUser;
> var groupname : string;
> Begin
> groupname := 'existinggroupname';
> dWorkspace := JetEngine.Workspaces.Item[0] ;
> dGroup := dWorkspace.Groups[groupname];
>
> with dWorkspace.Users[username] do begin
> groups.Append (dGroup);
Groups.Refresh 'refresh the Groups collection
Refresh; 'refresh the Users collection
> Free;
> end;
> dGroup.Free;
> dWorkspace.Free;
> JetEngine.FreeLocks;
> end;
>
>
> Has anyone any ideas of how you add a group to a user using DAO?
>
> Thanks
> Koyan
|
|
|
|
|