Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 18th, 2006, 04:24 AM
Authorized User
Join Date: Nov 2005
Posts: 41
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to RobCarter
Default User access levels without using the mdw

Hiya all.

I am trying to code some user access levels in whereby if a user has a certain access level (as defined in a field in a table) then the command buttons on my menus are enabled or disabled as required according to the value in the field.

I have a table with username, password and access level included in the fields and I guess that I have to use a module with a public variable, I am just unsure as to how I go about it.

Any response kindly appreciated

Rob Carter

Rob Carter
Rob Carter
Old April 18th, 2006, 08:11 PM
Friend of Wrox
Join Date: Mar 2004
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post

This is not real secure. Here is one way to do it. You will need a way to determine who the use is. You could use a log in screen and capture user's initials and PW and compare against the table entry, then set a Global variable for who the user is and what their permission level is. In the on_Load for your forms, check the user's permission level (Global)and set either the visible or enabled property for the control based on the Global permission level variable.

in a button on the User Log in Screen:
Dim db As DAO.Database
Dim rec As DAO.Recordset
Dim strUserPasswordInput As String ' hold password user gives to compare, Dim varFoundUserPW As Variant ' store user's PW
Dim strUserInitInput As String ' store user initials,
Dim strUserPWStored As String
Dim strUserInitStored As String
Dim intUserLevelStored As Integer

Set db = CurrentDb

Set rec = db.OpenRecordset("tblauthusers", dbOpenDynaset) ' updated 6-29-05

' make sure user performed!
If txtUserInit.Text <> "" Then
    strUserInitInput = txtUserInit.Text
    MsgBox "You must enter valid user initials and password"
    Exit Sub
End If

If txtUserPassword <> "" Then
        strUserPasswordInput = txtUserPassword
    MsgBox "You must enter valid user initials and Password"
    Exit Sub
End If

rec.FindFirst "[AuthInit] = """ & strUserInitInput & """"

If rec.NoMatch Then
    MsgBox "You have entered invalid User Initials or password."
Else ' user initials match
    strUserInitStored = rec("AuthInit")
    strUserPWStored = rec("Password")
    intUserLevelStored = rec("level")
End If

If strUserPWStored = strUserPasswordInput Then
    strUserInit = strUserInitStored ' set global
    intAuthLevel = intUserLevelStored ' set global, objects become visible depending on setting
    DoCmd.OpenForm "frmmainmenu"
    DoCmd.Close acForm, "frmUserID", acSaveNo
    MsgBox "You must enter valid user initials and PASSWORD"
    Exit Sub
End If

Set rec = Nothing

End Sub
The tblAuthUsers contains:
AuthID (PK)
AuthInit (Users Initials for Log in)
AuthName (users name)
Level (a long representing level of permission)
Password (text containing the PW)
an example of how to code a form's on_load event to allow a user with a specific level to see the button cmdOpenUpdateForm:

If intAuthLevel = 1 Then
    cmdOpenUpdateForm.Visible = True
    cmdOpenUpdateForm.Visible = False
End If
Create your Global variables in a module. You may want to call the module "Globals"

You may want to create a button or two for yourself to use during development that will re-set the permission level (such as if Level 6 is your highest level and allows you to do everything, code the button to reset the global variable to the value 6. WHEN something goes wrong during testing and your project gets reset after responding to a debug, you will loose your variable. Of course, before delivery, remove the button or set it to invisible.

The Following User Says Thank You to Loralee For This Useful Post:
RobCarter (June 24th, 2009)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Administer MS Access MDW file in VB.NET iii_carlos BOOK: Beginning VB.NET Databases 1 April 30th, 2007 06:25 AM
Access Database MDW iii_carlos BOOK: Beginning C# 2005 Databases 0 April 29th, 2007 02:17 AM
problem with access levels in application nav1 VB How-To 2 March 8th, 2005 05:17 PM
Security = System.mdw ?? martinaccess Access 5 November 13th, 2004 11:45 AM
user levels dazednconfused Beginning PHP 3 July 8th, 2003 04:29 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.