Want Command Button Visible For Certain User

Idris01

New member
Local time
Today, 19:27
Joined
Jun 10, 2011
Messages
9
Hi can anyone see what i am doing wrong with this code?

Private Sub Form_Load()
If Me.List19 = "John Hems" Then
Command11.Visible = True
Command7.Visible = False
Else
Command11.Visible = False
Command7.Visible = True
End If
End Sub

I want command11 visible if John Hems is in list19 and command7 visible at all other times

thanks
 
Re: Help

Your code is looking to see if "John Hems" is the item SELECTED in the list.

Are you trying to find out if "John Hems" in on the list even if that row is not selected?
 
Re: Help

And btw: "Help" is not a useful title for anything. Most ppl here post to obtain help, about something specific. Next time, write briefly what your issue is in the title - see any other post here. Then ppl can quickly see if they are able to help or not, and also others can have the benefit of the advice dispensed.
 
Re: Help

Hi guys, thanks for the replies, i am trying to hide command11 which is a button to open a form which only John should be able to open. I am trying to establish if John is the user logged on (list19) and if so his button will be visible, otherwise the command7 button for all other users is visible.

the reason for this is that only John needs access to certain commands on his form and we need to restrict others from using them

Idris
 
Re: Help

thanks, appreciate the info, was trying to get a quick response but understand it would be better to get a quick, meaningful response

Idris
 
Re: Help

Thanks Bob, will be able to do this later this week, makes sense now where i was going wrong.
 
Re: Help

Hi Bob. I've quoted your message below.
You should not be coding for him specifically. You should have a table which has the users that can have special access (Network Login Name) and then you use some code to set that -

Code:
Dim rst As DAO.Recordset
 
Set rst = CurrentDb.OpenRecordset("Select * From tblAuthUsers)
 
Do Until rst.EOF
   If rst!NetworkLogin = VBA.Environ("username") Then
       Me.Command11.Visible = True
       Exit Sub
   Else
       Me.Command11.Visible = False
   End If
   rst.MoveNext
Loop
 
rst.Close
Set rst = Nothing

So in this example you have a table named tblAuthUsers and there is one field named NetworkLogin. If the person logged into that computer is in the table then the button is made visible and if not it isn't.

I followed your instructions. The only change I made was adding the speechmarks in red below to make it work.
Set rst = CurrentDb.OpenRecordset("Select * From tblAuthUsers")

It works brilliantly! The only thing is I would like the username to be the username I used to log in to the database (I made a login form with password) rather than my user name on the PC.
Any help would be greatly appreciated.
Sam
 
Hi, I have stumbled across this thread,

I am trying to do something similar to this, I have a login screen which I have connected to a login table;
There will b only one specific user who can delete entries from any of the other tables, so basically I want to have a form for each table and I'll have navigation buttons etc on these forms,

However I would like each form to have a delete button, but that button should only be visible to a certain user

Would I be able to alter use this code to do this, and if so, where do I attach the code to (Each delete butt, form etc?)

Sorry if that's not ver specific, this is my first post on here
 
Thanks for posting this boblarson as it helped me massively with my DB!!

Cheers :):):):)
 

Users who are viewing this thread

Back
Top Bottom