Invisible buttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form in a secured dtabase and I'd certain buttons to be invisible
when user "bdavis" is logged in. How can I do this?
 
Write the code on the onload event of the form
If user = "bdavis" then
me.ButtonName.visible=false
else
me.ButtonName.visible=true
End if
 
In the form's Load event, put logic like:

Me.cmdButton1.Visible = (CurrentUser <> "bdavis")
Me.cmdButton2.Visible = (CurrentUser <> "bdavis")
 
To get the user name, do you use the currentuser, or did you created a
variable called user?
In any case, you can put a code break in the If statement to view the value
of user, or the current user, and you can step the code by pressing the F8
key, to see what happen.
If you use the currentuser provided by access then change the user to
currentuser, in the IF statement.
 
Ok, that worked... What would the code be if I wanted a command button to be
visible if the user was a member of the admin group?
 
It's an earlier post to get the groups which the user is in, just add the
criteria for the group you looking for and return true with the function to
determine if the fields should be displayed

'----- start of code -----
Function fncUserGroups() As String

' Returns a comma-separated list of the security groups of which
' the current user is a member.

' NOTE: Requires a reference to the DAO Object Library.

Dim ws As DAO.Workspace
Dim grp As DAO.Group
Dim strGroups As String

Set ws = DBEngine.Workspaces(0)
fncUserGroups =false
For Each grp In ws.Users(CurrentUser).Groups
If grp.Name = "admin" Then
fncUserGroups = True
exit function
end if
Next grp

Set ws = Nothing

fncUserGroups = Mid(strGroups, 3)

End Function
'----- start of code -----

Then you could set the ControlSource of your text box to

If fncUserGroups() Then
me.button.visible=false
else
me.button.visible=true
endif


I hope that helped and answered your question
 
Well, it seems like it always takes two times form me to get things right.
I'm sure I'm doing something wrong here but I pasted that code into a module
and then, as a test, set fncUserGroups() as control source for a text box but
it doesn't return any data... any ideas?
 
Back
Top