Solved

From security workgroup to login form in MS Access

Posted on 2013-01-03
5
445 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Access printing shortcut in Ms Access 10 35
microsoft access - xml 10 26
Calculating Business Hours 19 65
Access MDB/PDF 21 32
Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now