Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

From security workgroup to login form in MS Access

Posted on 2013-01-03
5
Medium Priority
?
457 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Ready to get certified? Check out some courses that help you prepare for third-party exams.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

972 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