Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

From security workgroup to login form in MS Access

Posted on 2013-01-03
5
Medium Priority
?
455 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
[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
  • 3
  • 2
5 Comments
 
LVL 85
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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 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 85
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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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