validate current user to table of approved users

S

Steve in MN

I want to put a check box on a form but only want that check box (and label)
to be visible to certain people because it is a finalization of a process.

So I have the Module for current user set up in the DB.

In the On_Load property of the form, I want to have the code check the
"current User" against a list of "Users" from table "Admin_Users" and if the
current user (from NT login) equals one of the "Users" from the "Admin_Users"
table then that check box and label would be visible. If the current user is
not on the list, then the check box and label would not be visilble.

I know this has to do with loops and I have not had any experience yet on
setting them up.

I know this is probably pretty easy and as soon as I see it I will click,
but I can't figure it out.


Thanks
 
S

Stuart McCall

Steve in MN said:
I want to put a check box on a form but only want that check box (and
label)
to be visible to certain people because it is a finalization of a process.

So I have the Module for current user set up in the DB.

In the On_Load property of the form, I want to have the code check the
"current User" against a list of "Users" from table "Admin_Users" and if
the
current user (from NT login) equals one of the "Users" from the
"Admin_Users"
table then that check box and label would be visible. If the current user
is
not on the list, then the check box and label would not be visilble.

I know this has to do with loops and I have not had any experience yet on
setting them up.

I know this is probably pretty easy and as soon as I see it I will click,
but I can't figure it out.


Thanks

No loops required here. The Dcount function will do the job for you.

Label.Visible = Dcount("*", "Admin_Users", "User='" & current_user & "'" > 0
checkbox.Visible = Label.Visible
 
J

Jack Leach

You should be able to use a Dlookup (or ELookup) and an if/then condition.
Something like this.

If IsNull(ELookup("Userfield", "adminstable", _
"[Userfield] = """ & YourNTUsername & """")) Then

Me.controltohide.visible = False
'or
Me.ControlToHide.Enabled = False
End If


What you may also want to do is put something in the controls Tag, like
"AdminControl", and loop the controls of the form:

(aircode)

Dim ctl As Control
If Not IsNull(ELookup........) Then
For Each ctl In Me
If ctl.Tag = "AdminControl" Then
ctl.Enabled = True
End If
Next
End If
Set ctl = Nothing


you may need some code in there to verify that it has a Tag property, I'm
not sure that all controls do, but this would be handy if you have a number
of controls.

hth

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
S

Stuart McCall

Stuart McCall said:
No loops required here. The Dcount function will do the job for you.

Label.Visible = Dcount("*", "Admin_Users", "User='" & current_user & "'" >
0
checkbox.Visible = Label.Visible

Oops. Slight correction:

Label.Visible = Dcount("*", "Admin_Users", "User='" & current_user & "'") >
0
checkbox.Visible = Label.Visible

(I missed the terminating paren for the dcount function call)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top