Cannot append new User

mary.h

Registered User.
Local time
Today, 13:56
Joined
Aug 21, 2003
Messages
48
Hi,

what I want to do is, that a person fills in in a table , i.e. form new members of a group named "Pool" and then this new members shall be dynamically set up as new users in my system.mdw

I get an error message, wenn appending the new member, saying "Operation not valid". What is wrong.

That is my Code:
Code:
Private Sub Form_AfterUpdate()
'is called, when a new record has been added to my table

On Error GoTo Err_this_Proc

'create new user or append user to usergroup Pool
New_PoolUser Me.Mitglied

Exit_this_Proc:
    Exit Sub
    
Err_this_Proc:
    MsgBox Err.Description, vbCritical, "LUKAS"
    Resume Exit_this_Proc
    
End Sub

Function New_PoolUser(strLogin As String)
Dim usrNew As User
Dim wrkSp As Workspace

On Error GoTo Err_this_Proc

Set wrkSp = DBEngine.Workspaces(0)

If UserInGroup("Pool", strLogin) = True Then
    'User is already a member of Pool
    Set wrkSp = Nothing
    Exit Function
Else
'if new user has no Account, create new account
'else append user to usergroup Pool
    If UserInDB(strLogin) = True Then
            [COLOR=Red]wrkSp.Users(strLogin).Groups.Append wrkSp.Groups("Pool")[/COLOR]  ' ERROR LINE
    Else
        'create new user
        Set usrNew = wrkSp.Groups("Pool").CreateUser(strLogin, "POOL")
        wrkSp.Groups("Pool").Users.Append usrNew
    End If
End If

Set usrNew = Nothing
Set wrkSp = Nothing

Exit_this_Proc:
    New_PoolUser = True
    Exit Function

Err_this_Proc:
    MsgBox Err.Description, vbCritical, "LUKAS"
    New_PoolUser = False
    Resume Exit_this_Proc
    
End Function

Function UserInDB(Login As String)
' Check if the current user is in the current DB

Dim w As Workspace
Dim U As User
Dim g As Group
Dim uname As String

On Error Resume Next

Set w = DBEngine.Workspaces(0)
' Read user object for the given user (wuking grate array!)
Set U = w.Users(Login)

uname = U.Name ' Name from groups list
    
    If uname = Login Then
        ' User has account, return success
        UserInDB = True
    Else
        ' User has no account, return failure
        UserInDB = False
    End If

Set U = Nothing
Set w = Nothing

End Function
 
Last edited by a moderator:

Users who are viewing this thread

Back
Top Bottom