473,404 Members | 2,179 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,404 software developers and data experts.

Locking fields per user rights

2 2Bits
Im trying to restict user from certain groups and only allowing them to fill in certain fields. but it seems that the code i have allows all user to enter data can some one help me. the code <
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub Form_Load()
  4.  
  5. 'dim the control
  6. Dim ctl As Control
  7. 'If the user is in admin do not lock the fields.
  8.     If IsUserInGroup(1) Then
  9.     'dont lock the form
  10.  
  11. For Each ctl In Me.Controls
  12.     If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
  13.         ctl.Locked = True
  14.         ctl.BackColor = RGB(200, 200, 200) 'grey
  15.     End If
  16. Next
  17. End If
  18.  
  19. 'Production Users unlocked fields
  20.  
  21. If IsUserInGroup(4) Then
  22.     TSubmittedDate.Locked = False
  23.     TRequestor_Name.Locked = False
  24.     TDepartment.Locked = False
  25.     TAreaAffected.Locked = False
  26.     TProjectSummary.Locked = False
  27.     TProjectDetails.Locked = False
  28.     TContactPhoneNo.Locked = False
  29.     TDepartmentManager.Locked = False
  30.     TReqCompletedDate.Locked = False
  31.     TSubmittedDate.BackColor = vbWhite
  32.     TRequestor_Name.BackColor = vbWhite
  33.     TDepartment.BackColor = vbWhite
  34.     TAreaAffected.BackColor = vbWhite
  35.     TProjectSummary.BackColor = vbWhite
  36.     TProjectDetails.BackColor = vbWhite
  37.     TContactPhoneNo.BackColor = vbWhite
  38.     TDepartmentManager.BackColor = vbWhite
  39.     TReqCompletedDate.BackColor = vbWhite
  40. End If
  41.  
  42. End Sub
  43. Function IsUserInGroup(GroupID As Long) As Boolean
  44.  
  45.     If IsNull(Forms!Main_Form!txtUserID) Then
  46.         IsUserInGroup = False
  47.         Exit Function
  48.     End If
  49.  
  50.     Dim X As Long
  51.     X = Nz(DLookup("ID", "GroupXUserT", "UserID=" & Forms!Main_Form!txtUserID & " AND GroupID=" & GroupID))
  52.  
  53.     If X > 0 Then
  54.         IsUserInGroup = True
  55.     Else
  56.         IsUserInGroup = False
  57.     End If
  58.  
  59.  
  60. End Function
  61.  
  62. Function CurrentUserId() As Long
  63.  
  64.     CurrentUserId = Forms!Main_Form!txtUserID
  65. End Function
Jul 10 '20 #1
5 2410
NeoPa
32,556 Expert Mod 16PB
It actually looks like you're locking out only administrators.

Line #13 should probably read :
Expand|Select|Wrap|Line Numbers
  1. ctl.Locked = False
That would rely on the Form being set to being locked up by default though.

NB. You should not proceed with any coding until you've read Require Variable Declaration.
Jul 11 '20 #2
NeoPa
32,556 Expert Mod 16PB
PS. Lines #53 through #57 could more easily be just :
Expand|Select|Wrap|Line Numbers
  1. IsUserInGroup = (X > 0)
Jul 11 '20 #3
isladogs
456 Expert Mod 256MB
Suggest you use the Tag property to simplify the code used in your code section If IsUserInGroup(4) - lines 21-40.
Assign each of the controls which you want to modify in the same manner with the same tag value e.g. G4. Then loop through the controls and if tag value ="G4", set locked = false and backcolor= vbWhite

Expand|Select|Wrap|Line Numbers
  1. Dim ctrl As Control
  2. For Each ctrl In Me.Controls
  3.      If ctrl.Tag = "G4" Then
  4.     ctrl.Locked=False
  5.     ctrl.BackColor=vbWhite
  6.      End If
  7. Next ctrl
Jul 11 '20 #4
3dcad2011
2 2Bits
whats the tag property
Jul 13 '20 #5
isladogs
456 Expert Mod 256MB
The tag property can be applied to one or more form controls and can be used for various purposes.
See the MS documentation about the tag property https://support.microsoft.com/en-ie/...on%20a%20form. and https://docs.microsoft.com/en-us/off...ccess.form.tag
Jul 13 '20 #6

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

Similar topics

0
by: Mark1 | last post by:
Hi, as I did not find a group for MySQL I try my luck here. Plz tell me, if there is a better cathegory for MySQL... I´ve got several MySQL Databases running on a Linux 8.1 Server. User...
1
by: simo sentissi | last post by:
Hello I have a vb.net app from where I send emails using the smtp .net class. I was developping it under my user rights (admin), but when I run it as a normal user it faces an error of the sort...
12
by: Quentin Huo | last post by:
Hi: I am working in win 2003 and ASP.NET. I tried to modify the user rights from an ASPX (writen in C#) page through running xcacls. But failed. What I did is: Process myProcess = new...
5
by: Andy | last post by:
Hi What user rights are necessary to run Vb.net 2005? I've tried to have only ordinary user rights when I start VB.net the first time and get some strange messages. /A.
0
by: poli | last post by:
Hi, I have a urgent problem. I want to end a running application before I start another one (in c# code). I see that all these function GetProcesses() ,GetProcessesByName(), run only if I have...
0
by: Keita | last post by:
Hi everyone. I'm using a socket-based application for Windows platforms (using winsock). Everything works fine when trying to connect in Administrator mode, but when I'm in User mode no communication...
1
by: nabilj45 | last post by:
Does anyone have a query that will list all the users and user rights for a sqlserver database. Thanks so much!
1
by: yellowblueyellow | last post by:
Hey ,, I wanted to List user rights assignment programmatically using c#.. the function should list the privilege and the user it has been granted to. I think it can be done using PInvoke . Is...
2
by: Jassim Rahma | last post by:
I have an application in C# and I want to assign rights based on the user login. I have users table in the database and I wnat to know what is the best way to manage the user rights?
7
zmbd
by: zmbd | last post by:
For establishing user "rights" in the past, I've use a ton of different methods: user security model, tables and related tables, and so forth The ms access user-level security had the advantage...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.