Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / November 2006

Tip: Looking for answers? Try searching our database.

Button visibility

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Spencer - 13 Nov 2006 22:04 GMT
I have made my own switchboard, and want one of the buttons and its label to
only be visible if either a certain user is signed on, or if the user is an
admin. I would appreciate the code to do it either way as I'm not sure which
I am going to do. Thanks in advance for your help.
Tom Wickerath - 14 Nov 2006 04:36 GMT
Hi Spencer,

Use the Form_Open event procedure. Something like this, where NTUserID1 and
NTUserID2 represent the NTUser ID's that these people use to log into Windows:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ProcError

Dim strUserName As String
strUserName = fOSUserName

Select Case strUserName
   Case "NTUserID1", "NTUserID2"   'These people can see the buttons
       Me.lblLabelName.Visible = True
       Me.cmdButtonName.Visible = True
   Case Else
       Me.lblLabelName.Visible = False
       Me.cmdButtonName.Visible = False
End Select

ExitProc:
   Exit Sub
ProcError:
   MsgBox "Error " & Err.Number & ": " & Err.Description, _
         vbCritical, "Error in procedure Form_Open..."
   Resume ExitProc
End Sub

You can grab a copy of the fOSUserName function here:

    Get Login name
    http://www.mvps.org/access/api/api0008.htm

> I would appreciate the code to do it either way...
The SELECT CASE part of the code would be similar if you are using ULS (User
level security) in Access. However, I tend to avoid using ULS, so you'll need
to work out how to grab the logged on user. I think it might be the
CurrentUser function, so instead of Select Case strUserName, you would have
Select Case CurrentUser, and you would not need the fOSUserName function.

Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

> I have made my own switchboard, and want one of the buttons and its label to
> only be visible if either a certain user is signed on, or if the user is an
> admin. I would appreciate the code to do it either way as I'm not sure which
> I am going to do. Thanks in advance for your help.
Spencer - 15 Nov 2006 22:10 GMT
I want to be able to use the name they sign into the database with. How do I
write the code to get the access name they use?
Tom Wickerath - 16 Nov 2006 02:12 GMT
Hi Spencer,

The code I gave you works for identifying an individual based on their
Windows NT UserID. If you are using User Level Security withing Access, then
making a call to the CurrentUser function should do the trick. Something like
this:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ProcError

Select Case CurrentUser
   Case "admin"   'These people can see the buttons
       Me.lblLabelName.Visible = True
       Me.cmdButtonName.Visible = True
   Case Else
       Me.lblLabelName.Visible = False
       Me.cmdButtonName.Visible = False
End Select

ExitProc:
   Exit Sub
ProcError:
   MsgBox "Error " & Err.Number & ": " & Err.Description, _
         vbCritical, "Error in procedure Form_Open..."
   Resume ExitProc
End Sub

I suppose another possibility might be that whoever designed your database
came up with a home-grown form of security, with usernames and passwords
perhaps stored in a table. In that case, one would likely need to store the
logged on userid in a global variable (split database, of course, where each
user has their own copy of the front-end application), and then use this
value in the SELECT Case statement.

Tom Wickerath
Microsoft Access MVP

http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________

> I want to be able to use the name they sign into the database with. How do I
> write the code to get the access name they use?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.