Solved

From security workgroup to login form in MS Access

Posted on 2013-01-03
5
450 Views
Last Modified: 2013-03-01
hi,

I've got this little challenge this week.

I do have a MS Access built in 2003 using security workgroup. There is a function called "displayRights" with the following attribute

Public Function displayRights (userName As String) As Boolean
    displayRights = GetUserBoolValue(userName, "DisplayPrices")
End Function.

This is used to get the logged in username from that Workgroup and determine if he can access the price tags in other forms where VBA calls this variable.

What I would like to do is to create the same global variable (instead of changing the whole vba on each form.

I have create a login form, that calls a table where is myUser and myPassword. In the same table there is a field where I do specifiy (0 or -1) if the logged in user has right to access price tags.

The question is How can I store this login information so I can call it every time a form is opened and make sure the proper right is applied.
0
Comment
Question by:SirTKC
  • 3
  • 2
5 Comments
 
LVL 84
ID: 38742498
First: If you're using "a table where is myUser and myPassword." then you're not using User Level Security (or "workgroup" security). You're using home-grown security. There's nothing wrong with that, but it's best to be explicit when describing your situation to others.

I don't really understand what you're asking. You can call the "displayRights" function from anywhere in the project, assuming it's stored in a Standard Module. You'd use it something like this:

If displayRights("YourUserName") = True Then
  '/ do something here
Else
  MsgBox "You don't have permission to open this form"
End If

If you're asking how to "store login information" then, again, I don't really understand. If you have a User table, then you could simply include a boolean field named IsLoggedIn, and set that value to True whenever someone logs in. This can be troublesome at times - for example, if the program crashes, you'd have to reset that field to False for all users in order to start back fresh.

If all you want to do is just store the UserName of the person who logged in, then the simplest way to do that is with a hidden form. Add a textbox to that form named "txUser", and set the value of that textbox when the user successfully logs in. You can then refer to that textbox as needed:

If Forms("YourHiddenForm").txUser = "Scott" Then
  '/ do something here
End If
0
 
LVL 3

Author Comment

by:SirTKC
ID: 38742510
THanks for your advise,

I will try to be more explicit.

In fact, I WAS using "User Level Security" ando NOT anymore since I have created a seperate table where I do store username and passwords as well as "displayRights" (field)

I just want to be able to display certain controls depending if "displayRights" is checked or not based on the logged in user.

I would like to explain it in a more simple english, but my french prevent me to do so ! :-)

My apologies ;)
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 38742539
Okay - so you're logging in users with your own system, and you need to store the "logged in user"? If so, then the hidden form trick is the most reliable way to manage this.

Build a form named "frmHidden". On that form, add a textbox named "txUser". Set this form to start when the application starts, and make sure it's hidden. I assume you have a login form, so you'd open the hidden form when the user has successfully entered their password:

DoCmd.OpenForm "frmHidden", , , , , acHidden

Now write the user value to that form:

Forms("frmHidden").txUser = Me.YourUserNameField

Now you can refer to that form anywhere in your application like this:

Forms("frmHidden").txUser

So if you need to determine if the currently logged in user has display rights:

If displayRights(Forms("frmHidden").txUser) = True Then
  '/ the user can see the prices
Else
  '/ the user cannot see the prices
End If
0
 
LVL 3

Author Comment

by:SirTKC
ID: 38742549
And what if I already have another form set to start when the app is launched ?
0
 
LVL 84
ID: 38743195
Just open frmHidden in that form's Open or Load event. However, if you have a login mechanism, it's easiest to open frmHidden when the user credentials have been validated.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

808 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