Solved

Using MS Access security via vb code

Posted on 1998-07-23
2
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2013 combo box not working 3 73
Add a task in Outlook from access 11 43
VBA Shell can't Find Word document 11 155
Problem to line 23 79
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

737 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