• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 462
  • Last Modified:

From security workgroup to login form in MS Access

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
SirTKC
Asked:
SirTKC
  • 3
  • 2
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
 
SirTKCAuthor Commented:
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
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
 
SirTKCAuthor Commented:
And what if I already have another form set to start when the app is launched ?
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now