By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,395 Members | 1,451 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,395 IT Pros & Developers. It's quick & easy.

Disabling and Enabling Form buttons

P: 33
I have a table with a field called DEPT_ACCESS. I also have a form called FRMACCESS with 3 buttons called DEPT_1, DEPT_2 and DEPT_3. I want to write a code such that when a user from whose DEPT_ACCESS is 1 opens the FRMACCESS, only the button called DEPT_1 should be enabled. Similarly, user whose DEPT_ACCESS is 2 should have only button called DEPT_2 enabled. The same criterion holds for user with DEPT_ACCESS 3. The name of the table is called TBLADMIN.
Aug 4 '08 #1
Share this Question
Share on Google+
3 Replies

P: 23
If you have implemented Microsoft Access Security then you can get the name of the Form's current user name with the Function CurrentUser. But you must be able to identify a particular user with the department and accordingly you can enable or disable Buttons.
Expand|Select|Wrap|Line Numbers
  1. if currentuser = "xyz" and [Deptt]="DEPART_1" then
  2.    me![DEPART_1].enabled = true
  3. end if
try the following link for Microsoft Access Security implementation
Aug 4 '08 #2

Expert Mod 15k+
P: 31,661
How does the code know which department the user is in?

I assume TBLADMIN must enable you to translate a user name into a department (although you don't say so in the question), but how do you propose to determine who the user is in the first place? It's possible of course, but the problem is there are a number of ways it COULD be done. How are YOU planning to do it?
Aug 10 '08 #3

P: 122
Here's a function I found when I needed to know which user was currently logged in.

Expand|Select|Wrap|Line Numbers
  1. Public Function CNames(UserOrComputer As Byte) As String
  2.     'UserorComputer; 1=User, anything else = computer
  3.     Dim NBuffer As String
  4.     Dim Buffsize As Long
  5.     Dim wOK As Long
  7.     Buffsize = 256
  8.     NBuffer = Space$(Buffsize)
  10.     If UserOrComputer = 1 Then
  11.         wOK = api_GetUserName(NBuffer, Buffsize)
  12.          CNames = Trim$(NBuffer)
  13.     Else
  14.         wOK = api_GetComputerName(NBuffer, Buffsize)
  15.         CNames = Trim$(NBuffer)
  16.     End If
  17. End Function
It's working great for me. I hope you find it useful as well. Wish I could give credit where credit was due, but I can't remember where I found this.
Aug 10 '08 #4

Post your reply

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