Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error creating Users In Code

Status
Not open for further replies.

MadJock

Programmer
May 25, 2001
318
0
0
GB
Hi Folks,

I have a secured access 97 database with three user groups set up - Admins, Users and SparkAdmins. The owner is me (GTAYLOR) and I am a member of the Admins Group.

At present, all three user groups have full access for every object in the database until I resolve the problem that I'm about to explain.

The database is associated to a workgroup (sspark.mdw) via the /wrkgrp command line switch in the shortcut. My PC is not joined to the workgroup.

Using the MS Access "User and Group Accounts..." functionality, I can quite easily add / delete users and groups. The performance of this part is exactly as I expect.

I have a form which should allow users to add new users to the system by typing the new username in a textbox and selecting the group from a drop-down menu.

The code behind the form is as follows:
Code:
  Dim owrk As DAO.Workspace
  Dim ouser As DAO.User
  Dim ogroup As DAO.Group
  Dim strPassword As String


    If ((Len(Me.txtLogin) = 0) Or (Len(Me.cboGroup) = 0)) Then
        MsgBox "Please specify login and group!"
    Else

        Set owrk = DBEngine.Workspaces(0)   
        
        Set ouser = owrk.CreateUser(Me.txtLogin, Me.txtLogin & "_PID", "")
        owrk.Users.Append ouser  '*****
        
        Set ogroup = ouser.CreateGroup(Me.cboGroup)
        ouser.Groups.Append ogroup


    End If

When this code is executed, I get "Error 3358 - Cant't read the workgroup information file" at the line I have marked with asterisks. I am logged in as GTAYLOR at the time (the owner - see above)

On further analysis, I have also found the following:
DBEngine.SystemDB is "system.mdb" (not a typo!)
DBEngine.Workspaces(0).Groups.Count is 0
DBEngine.Workspaces(0).Users.Count is 0
DBEngine.UserName and Workspaces(0).UserName are both shown as "admin"

When setting up the security, I followed word-for-word the steps laid out on the Microsoft web-site.

As always, any help would by greatly appreciated!

Graeme





website:
 
Hi MadJock

Heres try this, its a piece of code I've used myself and works fine.

Make sure you log in using a shortcut like the following OR change the default workgroup file in WorkGroup Aministrator

"C:\Program Files\Microsoft Office\Office\msaccess.exe" "[DbPath & Name]" /wrkgrp "[.mdw Path & Name]"

'User Add Code
Dim ouser As User

Set ouser = DBEngine(0).CreateUser([username])
With ouser
.PID = [PID]
.Password = [Password]
DBEngine(0).Users.Append ouser
.Groups.Append .CreateGroup("Users") 'Name of group to add user to
If cboGroup <> &quot;Users&quot; Then
.Groups.Append .CreateGroup([GroupName])
End If
End With
MsgBox &quot;User Created&quot;, vbInformation, &quot;Successful&quot;

Hope this helps... [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top