Restricting Tab Controls based on user

NauticalGent

Ignore List Poster Boy
Local time
Today, 12:56
Joined
Apr 27, 2015
Messages
6,994
Hello all,

I am trying to do something neat with one of my forms and I am a little out of my league here (as usual)

I have a form with 4 tabs. What I want to do is set the Visible property to False for three of these if the user is not part of an office code.

To do this I used the following code on the Main Form's On Load Event:

TabControl(1).Visible = False
TabControl(2).Visible = False
TabControl(3).Visible = False

Works like a charm. However I want to make it conditional based on a user's Office Code: N41.

To accomplish this I made a function that reads the user's Computer Access Card to obtain the users name: ReturnUserName()

I have a table (tblUsers) that contains fields that store the user's name and Office Code: UserName & OfficeCode.

What I want to do is have the application check the office code assigned to the user and if it does not equal "N41" then TabControls 1-3 will not be visible.

I have tried to use DLookUp to do this but have not been able to make it work.

Any and all suggestions would be MUCH appreciated!
 
something like this in your form's load event:

dim intCount As Integer
Dim strUser As string

strUser = ReturnUserName()
intCount = NZ(DCount("*","tblUsers","[UserName] = '" & strUser & "' And [OfficeCode]='N41'"), 0)
TabControl(1).Visible = (IntCount>0)
TabControl(2).Visible = (IntCount>0)
TabControl(3).Visible = (IntCount>0)
 
DUDE! Worked liked something that works well! Thanks for the quick reply and thanks again for the code!

Going to have to do some research as to WHY it works but for now, I will just have to use it and let everyone think I am a genius.

Thanks again!
 
your welcome sir!
 
I did some research on the NZ function. I appears you used it as a sort of IIF statement...pretty slick!

Again, thank you so much. I ope others will see this post and gain from it to. This site is the freaking bomb...:cool:
 
NZ(DCount("*","tblUsers","[UserName] = '" & strUser & "' And [OfficeCode]='N41'"), 0)

Count the records in tblUsers Where the Username = ReadFromCard and the OfficeCode = 'N41'

NZ = NullZero so if your count is NULL it returns 0

IntCount can then be 0 or >0 so

Where the IntCount is >0 = TRUE VISIBLE = TRUE

Or something like that

Cheers!
Goh
 
is this by establishing relationships or is it by concatenation?
 
Neither. I simply have a function that will obtain the users name from there access card and then checks the users table to see If thier assigned office code is "N41"
 
How do you do that? I cannot even imagine to do something like that
 

Users who are viewing this thread

Back
Top Bottom