|
-
May 4th, 2000, 06:20 PM
#1
Thread Starter
Lively Member
Hi
I'm building a database in access and have a form which is intended to be used for adding a new user.
However on execution the database doesn't recognise the workspace/user data types and produces a sub or function not defined error on reaching the line with CreateUser.
The method is applicable in Jet workspaces only. Do I have a missing reference?
I have included my code below:
Private Sub cmdAddUser_Click()
Dim wrkDefault As Workspace
Dim usrNew As User
Dim usrTemp As User
Dim strUserName As String
Dim strGroup As String
Dim strPassword As String
Dim strPID As String
Dim intRandom1 As Integer
Dim intRandom2 As Integer
Dim intRandom3 As Integer
Dim intRandom4 As Integer
Dim intRandom5 As Integer
Dim intRandom6 As Integer
Dim intRandom7 As Integer
Dim intRandom8 As Integer
Dim intRandom9 As Integer
'initialize random-number generator
Randomize
'generate random value between 1 and 9
intRandom1 = Int((9 * Rnd) + 1)
intRandom2 = Int((9 * Rnd) + 1)
intRandom3 = Int((9 * Rnd) + 1)
intRandom4 = Int((9 * Rnd) + 1)
intRandom5 = Int((9 * Rnd) + 1)
intRandom6 = Int((9 * Rnd) + 1)
intRandom7 = Int((9 * Rnd) + 1)
intRandom8 = Int((9 * Rnd) + 1)
intRandom9 = Int((9 * Rnd) + 1)
'get the user name
strUserName = Chr(34) & txtUserNameAdd & Chr(34)
'get the group
strGroup = Chr(34) & txtGroup & Chr(34)
'get the password
strPassword = Chr(34) & txtPassword & Chr(34)
'generate a PID for the new user
strPID = Chr(34) & Left(strUserName, 3) & intRandom1 & intRandom2 & intRandom3 & intRandom4 & intRandom5 _
& intRandom6 & intRandom7 & intRandom8 & intRandom9 & Chr(34)
Set wrkDefault = DBEngine.Workspaces(0)
With wrkDefault
'create and append new user
Set usrNew = CreateUser(strUserName)
usrNew.pid = strPID
usrNew.Password = strPassword
.Users.Append usrNew
'add the new user to a group
Set usrTemp = .groups(strGroup).CreateUser(strUserName)
.groups(strGroup).Users.Append usrTemp
End With
End Sub
Any help would be most appreciated as this is one of the last things I have to do and I'm stuck until I can get it done.
Best Regards
Rob Brown
-
May 5th, 2000, 01:43 AM
#2
Hyperactive Member
A couple quick thoughts... If you’re using a jet 1.x created workgroup information file, you can't use the Groups collection of a User object; you'll need to recreate using 2+. Otherwise in your "With wrkDefault," a loop to add a group when it doesn't exist and a period may help.
Dim iNotbeGrp As Boolean, grpLoop As Group
iNotbeGrp = True
For Each grpLoop In usrNew.Groups
If grpLoop.Name = strGroup Then
iNotbeGrp = False: Exit For
End If
Next grpLoop
If iNotbeGrp Then
Set grpNew = .CreateGroup(strGroup, [id?])
.Groups.Append grpNew
End If
.
.
.
Set usrNew = .CreateUser(strUserName)
Hope this helps.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|