Solved

Using MS Access security via vb code

Posted on 1998-07-23
2
225 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

Technology Partners: 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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

617 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