Create a New User PID with Code

  • Thread starter Thread starter Tony_VBACoder
  • Start date Start date
T

Tony_VBACoder

In Access 2002, how you can create the PID (Personal ID)
for New User with VBA Code? I am creating a Form where an
Admin can add a New User, but I don't know how to set the
PID for that user, like I can if I use the Security
Form "User and Group Accounts" to add a new user. My
function to add a user is below:

Function CreateUsers(sUserName As String, sPassword As
String) As Boolean
Dim cat As ADOX.Catalog

On Error GoTo CreateUsers_Err

CreateUsers = True

Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection

' Add User to the Users collection of the Catalog object
cat.Users.Append sUserName, sPassword

CreateUsers_Exit:
Set cat = Nothing
Exit Function

CreateUsers_Err:
MsgBox "Error # " & Err.Number & ": " & Err.Description
CreateUsers = False
Resume CreateUsers_Exit

End Function
 
Ok, I changed my function to this:

********************************************************
Function CreateUsers(sUserName As String, sPassword As
String, sPID As String)
Dim conDatabase As ADODB.Connection
Dim sSQL As String

Set conDatabase = Application.CurrentProject.Connection
sSQL = "CREATE USER " & sUserName & " " & sPassword & " "
& sPID
conDatabase.Execute sSQL

End Function
********************************************************

Can you not set the PID property via the
Catalog/Users/Append method with ADO?
 
Hum, you can use dao to do this, like:


Public Sub CreateRidesUser(strUser As String, strPID as string)

'-----------------------------------------------------------
' Create a new user and add them to the Users group
' Returns True on success, False if user already exists
'===========================================================

Dim db As Database
Dim ws As Workspace
Dim usr As user
Dim grpUsers As Group


Set ws = DBEngine.Workspaces(0)
ws.Users.Refresh
' go ahead and create the user account


Set usr = ws.CreateUser(strUser, strPID, "")
ws.Users.Append usr
ws.Users.Refresh

' now add the user to the Users group
Set grpUsers = ws.Groups("Users")
Set usr = grpUsers.CreateUser(strUser)
grpUsers.Users.Append usr
grpUsers.Users.Refresh

End Sub
 
Back
Top