Solved

Using MS Access security via vb code

Posted on 1998-07-23
2
208 Views
Last Modified: 2010-05-03
I am currently using a secured ms access database and opening it within my vb application using a user name and password. I now want to know how can I create, modify & delete new users from the system.mda file using vb code and also have the capability to change password.
0
Comment
Question by:pcorreya
2 Comments
 
LVL 9

Accepted Solution

by:
Dalin earned 200 total points
ID: 1466490
pcorreya,
Try the following code. Let me know if you have any problems.
Regards
Dalin



const ADMIN_USERNAME = "Admin"
const ADMIN_PASSWORD = "adminpass (or whatever)"
const SHOWICON_STOP = 16



Function CreateNewUser% (ByVal username$, ByVal password$, ByVal PID$)

       '     '- create a new user.
       '     '- username$ - name
       '     '- password$ - user password
       '     '- PID$ - PID of user
       '     '-----------------------------------
       Dim NewUser As User
       Dim admin_ws As WorkSpace
       '     '=====================================
       '     '- check PID

              If (Len(PID$) < 4 Or Len(PID$) > 20) Then
                     MsgBox "Invalid PID", SHOWICON_STOP
                     CreateNewUser% = True
                     Exit Function
              End If

       '     '- verify that user does not yet exist

              If (UserExist%(username$)) Then
                     CreateNewUser% = True
                     Exit Function
              End If

       '     '- open new workspace and database as admin
       dbEngine.Workspaces.Refresh
       Set admin_ws = dbEngine.CreateWorkspace("TempWorkSpace",
        ADMIN_USER, ADMIN_PASSWORD)

              If (Err) Then
                     '     '- failed opening workspace
                     MsgBox "invalid administrator password", SHOWICON_STOP
                     MsgBox "Error: " & Error$, SHOWICON_STOP, SystemName
                     CreateNewUser% = True
                     Exit Function
              End If

       On Error Resume Next
       '     '- create the new user
       Set NewUser = admin_ws.CreateUser(username$, PID$, password$)

              If (Err) Then
                     MsgBox "Can't create new user.", SHOWICON_STOP
                     MsgBox Error$, SHOWICON_STOP
                     GoTo CreateNewUser_end
              End If

       '     '- add user to user list
       admin_ws.Users.Append NewUser
       '     '- add user to "Users" group
       Set NewUser = admin_ws.CreateUser(username$)
       admin_ws.Groups("Users").Users.Append NewUser
       admin_ws.Users(username$).Groups.Refresh
       admin_ws.Close
       CreateNewUser% = False
       CreateNewUser_end:
       On Error GoTo 0
End Function

0
 
LVL 1

Author Comment

by:pcorreya
ID: 1466491
Dalin

I failed to tell you that I was using VB 3, will this work.
I tried looking for the workspace object, but couldn't find it
in vb 3.

By the way what is PID, how do you get this.

Bye
Patrick
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question