473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Help needed for Open Form OpenArg

79 64KB
I am planning to set user privilege based on the user’s group after they logon. I need helps to correct my code or approach.

I created a table named TUSERID that consist of three fields: UserID, UserName, Password, and Department.

The database open with logon form. After user select their username, enter password and click the cmdLogin button, the event code check the password and user department then open the Main_0 form.

Depending on the user’s department, I want to show/hide selected buttons in the Main_0 form.

I use the DoCmd.OpenForm line with cmdVendorRpt = True/False to control user’s privilege. cmdVendorRpt is one of the buttons that I want to control user's ability to see.

However, this does not work. The Main_0 form opened with all buttons shown no matter what the user department is.

Please help. Below is my code.

Thanks

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdLogin_Click()
  2.  
  3. Dim MyPassword As String
  4. Dim MyGroup As String
  5.  
  6. 'Check to see if data is entered into the UserName combo box
  7.  
  8.     If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
  9.       MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
  10.         Me.cboEmployee.SetFocus
  11.         Exit Sub
  12.     End If
  13.  
  14.     'Check to see if data is entered into the password box
  15.  
  16.     If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
  17.       MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
  18.         Me.txtPassword.SetFocus
  19.         Exit Sub
  20.     End If
  21.  
  22.     'Check value of password in tblEmployees to see if this
  23.     'matches value chosen in combo box
  24.  
  25.     MyPassword = DLookup("[Password]", "TUSERID", "[UserID]=[cboEmployee]")
  26.     MyGroup = DLookup("[Department]", "TUSERID", "[UserID] = [cboEmployee]")
  27.  
  28.     If txtPassword = MyPassword Then
  29.  
  30.         DoCmd.Close acForm, "F_Logon", acSaveNo
  31.  
  32.             If MyGroup = "Admin" Then
  33.                 DoCmd.OpenForm "F_Main_0", , , , , , cmdVendorRpt = True
  34.  
  35.             Else
  36.                 DoCmd.OpenForm "F_Main_0", , , , , , cmdVendorRpt = False
  37.  
  38.             End If
  39.  
  40.     Else
  41.       MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
  42.             "Invalid Entry!"
  43.         Me.txtPassword.SetFocus
  44.  
  45.     End If
  46.  
  47.     'If User Enters incorrect password 3 times database will shutdown
  48.  
  49.     intLogonAttempts = intLogonAttempts + 1
  50.     If intLogonAttempts > 3 Then
  51.       MsgBox "You do not have access to this database.Please contact admin.", _
  52.                vbCritical, "Restricted Access!"
  53.         Application.Quit
  54.     End If
  55.  
  56.  
  57. End Sub
  58.  
  59.  
Aug 30 '13 #1

✓ answered by Seth Schrock

Only one question per thread please. Just post your "next question" in a new thread and we will be glad to help.

Back to the original question, I will try to help you out in a way that will fit in with your next question. What would probably be simplest would be to just use MyGroup as the value for the OpenArgs property. That way you can get rid of the If/Then/Else statement. So your lines 32-38 can be replaced with
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm FormName:="F_Main_0", OpenArgs:=MyGroup
Then in F_Main_0's OnLoad event, you would use a Select Case statement to test for the OpenArgs value.
Expand|Select|Wrap|Line Numbers
  1. Select Case Me.OpenArgs
  2.     Case "Admin"
  3.         cmdVendorRpt.Visible = True
  4.  
  5.     Case "Other Group Name"
  6.         cmdVendorRpt.Visible = False
  7.  
  8. End Select
The down side of doing things this way is that everything is hard coded for what each group can do and also what groups there are. If you want to add a group for some reason down the road, you need to edit your code to look for a new group name. The up side is that it is probably the simplest method to code.

5 1318
Seth Schrock
2,965 Expert 2GB
The OpenArgs property doesn't allow you to make changes to the form directly. It only allows you to pass a value to the form. What you need to do is come up with a set of values (such as "Admin"/"Other", "True"/"False", 1/0, etc.) that you can test in F_Main_0's OnLoad event. Based on the value in the OpenArgs property of the form, you can then set your button's visible properties to true or false.
Aug 30 '13 #2
Joe Y
79 64KB
Thanks Seth. Can you provide more hint or code example?

Your answer also inspired me for the next question:

Once user entered ID and password, is there a way that their ID and department (group) become global variance? This way, other forms can easily use these variances for user privilege setting. If this can be done, how and where to set the global variance?

Thanks again.
Aug 30 '13 #3
Seth Schrock
2,965 Expert 2GB
Only one question per thread please. Just post your "next question" in a new thread and we will be glad to help.

Back to the original question, I will try to help you out in a way that will fit in with your next question. What would probably be simplest would be to just use MyGroup as the value for the OpenArgs property. That way you can get rid of the If/Then/Else statement. So your lines 32-38 can be replaced with
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm FormName:="F_Main_0", OpenArgs:=MyGroup
Then in F_Main_0's OnLoad event, you would use a Select Case statement to test for the OpenArgs value.
Expand|Select|Wrap|Line Numbers
  1. Select Case Me.OpenArgs
  2.     Case "Admin"
  3.         cmdVendorRpt.Visible = True
  4.  
  5.     Case "Other Group Name"
  6.         cmdVendorRpt.Visible = False
  7.  
  8. End Select
The down side of doing things this way is that everything is hard coded for what each group can do and also what groups there are. If you want to add a group for some reason down the road, you need to edit your code to look for a new group name. The up side is that it is probably the simplest method to code.
Aug 30 '13 #4
Joe Y
79 64KB
Now I understand the concept of passing value using OpenArg. Thanks!

You mentioned a different way to make it easier down the road when new groups are added without needs of hard coding. Could you let me know the approach or articles that discuss this subject?

I will post a new thread regarding global variance.

Thanks,
Joe
Aug 30 '13 #5
Seth Schrock
2,965 Expert 2GB
Glad to hear it. Our goal is to help you in a way that helps you learn the topic and not just how to fix a specific problem. That way you can use your knowledge later on.

Glad to be able to help.
Aug 30 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jack Smith | last post by:
Help needed on this question. Any help is appreciated. Thanks in advance. Given a binary string (i.e. a finite sequence of 0's and 1's) we choose any two digit substring 01 and replace it by a...
1
by: Robert V | last post by:
Hi all, I could use some help programming on of my Perl script to handle different submit buttons within the same form. Here is what I have so far. A user goes to a Web form and inputs some data...
3
by: % =joe % | last post by:
I cannot get this code to work. Very simple...I have three list menus. I want to do a check before the form submits to make sure that the value of the 3 fields is equal to 12. Here's my...
7
by: TDIOwa | last post by:
I have a form that has a specific date on it. I want to open another form that has the Active Control Calendar on it. I want to open this form to the specific date on the first form. I have...
3
by: cefrancke | last post by:
Is there a way to list (through VBA code) all the controls on an open form including subforms, tab controls and all other containers as well. My specific issue is to find all controls with a...
2
by: chris.thompson13 | last post by:
Any good advice to help solve this problem would be most welcome. I can not open a recordset based on a query (called qryNoDateSetYet). The qryNoDateSetYet uses another query within it called...
2
by: erick-flores | last post by:
Hello all Form A (pk) & Form B (fk) I want to display my Form B empty whenever is the first time, that the pk form Form A, is enter. I click a button to open Form B. BUT if the pk from Form A...
3
by: kev | last post by:
Hi folks, I have a form for registration (frmRegistration) whereby i have two buttons. One is Save which saves record using the OnClick property. I used wizard to create the save button. The...
3
by: vidhyapriya | last post by:
Hi all I am developing windows application using vb.net.I want to pass values to open form.I am opening only one form when user click the buttons several times.Useing delegate i am passing...
13
by: deepunarayan | last post by:
Hi I have Problem in ASP. I have created a Multi choice Question page in ASP with Submit button. When I submit my page the User Selected values will be taken to the other page where validation...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.