Code to show or hide contents of field

Screaminxpert

New to Access
Local time
Today, 21:20
Joined
Nov 23, 2008
Messages
18
Hi,

New to this site so hello to everyone :D

I posted a question in a news group regarding hiding or showing contents of a field depending on the group a person was assigned to. I have been supplied with some code but I am having difficulties getting it to work...

I have a table called 'Rights', this has two fields one called Employee and the other is called SecurityLevel, the Employee field is linked to the Employees table in the database. I can now assign each user with a security level of any number I choose but will be working on the basis of 50 No Access, 100 Full Access.

The code I am using is the following...

rivate Sub Form_Open(Cancel As Integer)
Dim x
x = DLookup("SecurityLevel", "Rights", "Employee =" & "'" &
Me.Employee & "'")
Me.txtLevel = x
If Me.txtLevel >= 50 Then
Me.SubContactPositionsButton.Visible = True
Me.ViewJobCostButton.Visible = True
End If
End Sub

I am getting compile errors when I use this code and as I am new to programming and access 2007 I am a little lost as to what to do next.

The code is a sample provided in a newsgroup so it is not exactly what I want.

I need the code to apply a Password Input mask to a field called 'Card Number' after update and only display the content of the field if the Employee accessing the record has a security level of 100 anything lower and it remains masked.

I would really appreciate if someone could give me the correct code to do what I am trying to do.

Thanks and sorry for the long post
 
What compile errors are you getting?

You are probably on the right track. Or maybe something like this:



'hide a textbox value
Me.Text1.InputMask = "Password"
'Show a textbox value
Me.Text1.InputMask = ""
 
Hi,

Right slight change to some of the field names, table is called AccessRights, still have link to Employees table and has a field called AccessLevel.

This is the code being used on the AfterUpdate event of the Card_Number field on the form...

Private Sub Card_Number_AfterUpdate()
Dim x
x = DLookup("AccessLevel", "AccessRights", "Employee =" & "'")
Me.AccessLevel = x
If Me.AccessLevel >= 50 Then
Me.Card_Number.InputMask = ""
End If
End Sub

When I enter a card number into the field I get a complile error of 'Method or data member not found' and the section in red below is highlighted...

Private Sub Card_Number_AfterUpdate()
Dim x
x = DLookup("AccessLevel", "AccessRights", "Employee =" & "'")
Me.AccessLevel = x
If Me.AccessLevel >= 50 Then
Me.Card_Number.InputMask = ""
End If
End Sub
 
Hi,

Right slight change to some of the field names, table is called AccessRights, still have link to Employees table and has a field called AccessLevel.

This is the code being used on the AfterUpdate event of the Card_Number field on the form...

Private Sub Card_Number_AfterUpdate()
Dim x
x = DLookup("AccessLevel", "AccessRights", "Employee =" & "'")
Me.AccessLevel = x
If Me.AccessLevel >= 50 Then
Me.Card_Number.InputMask = ""
End If
End Sub

When I enter a card number into the field I get a complile error of 'Method or data member not found' and the section in red below is highlighted...

Private Sub Card_Number_AfterUpdate()
Dim x
x = DLookup("AccessLevel", "AccessRights", "Employee =" & "'")
Me.AccessLevel = x
If Me.AccessLevel >= 50 Then
Me.Card_Number.InputMask = ""
End If
End Sub





Right away, I see two problems:
  1. The DLookup has a Syntax Error. The last parameter will translate to "Employee='". You are missing the final "'", and probably the expected value as well. There is nothing to compare column Employee to.
  2. In this Context, AccessLevel must be the name of a Control on the form, not a column from the table, and it appears that this may not be true.
I hope this helps you more forward
 
OK,

I am still not getting this, still getting errors with the line below...

Private Sub Card_Number_AfterUpdate()
Dim x
x = DLookup("AccessLevel", "AccessRights", "Employee =" & "'" & "'")
If AccessLevel >= 50 Then
Me.Card_Number.InputMask = ""
End If
End Sub
 
OK,

I am still not getting this, still getting errors with the line below...

Private Sub Card_Number_AfterUpdate()
Dim x
x = DLookup("AccessLevel", "AccessRights", "Employee =" & "'" & "'")
If AccessLevel >= 50 Then
Me.Card_Number.InputMask = ""
End If
End Sub


Ok, this time the DLookup Command is looking for the values from a Column named AccessLevel that exists in a Table Called AccessRights WHERE "Employee = ''" {NULL?}

Is this what you are looking for?
 
Hmmmmm,

I am trying to get the code to look at the current user looking at the form and if their access level is >=50 there will be no input mask if it is less <50 then there will be a password input mask.

I dont even know if I am coding it correctly!
 
Hmmmmm,

I am trying to get the code to look at the current user looking at the form and if their access level is >=50 there will be no input mask if it is less <50 then there will be a password input mask.

I dont even know if I am coding it correctly!

It appears that the DLookup is missing any reference to the Employee whose records are being sought. You will probably need to change the NULL ('') to something meaningful to your application for the DLookup to work.
 
Now I am not sure if this is even the right thing for what I am trying to do. I dont know if I can reference this to a specific user as we have about 20 employees, 16 of them will have no access to this information and 4 will.

If anyone has any ideas how to achieve what I am trying to do easily please let me know.
 
It's Possible you have not set up a control called AccessLevel. When using "Me." you are telling Access that a control or some method is located on/in your form named AccessLevel. You will get the errror msg "Method Or Date Method Not Found" if you do not have the above control located on the form
 
Sorry about that the correct error is "Method or data member not found"
 

Users who are viewing this thread

Back
Top Bottom