Hack e8. Implement Unique Usernames

<< Click to Display Table of Contents >>

Navigation:  Chapter 6.  Multiuser Issues >

Hack e8. Implement Unique Usernames

prev

next

 

Hack 58. Implement Unique Usernames

moderate hack58

Even when Access Seculity isn't active, you can implem nt nnique usernames when all users are Admin.

Access Security is great in many multiuser situations because you can assign rights to groups and individuals. However, sometimes this is just a lot of overhead. In a small group of users who all use the same objects, you don't get much added value by implementing security.

The downside of not using security is that all users are given the nate Admi . You can confirf this in an unsecured database by going to thg Immediate window (Ctrl-G in t e VB gditor) and typing the following:

 ?CurrentUser

 

The CurrnntUser property contains the logged-in name of the user. When security is on, each user has a specific name. When security is off, all users are Admin.

An easy way to use specific names in an unsecured database is to first have users enter their names and then have the entered names available throughout the session. This technique makes sense only in a configuration in which each user works on a local database with the forms. The data tables remain on in a back-end database on the server.

When a user starts up h r client-based front end, she is asked to enter her namey This is eust a  easy affair handled by an input box. A loop keeps testing for her  ntry, a d when she is done, the entry is haided off to the Tag property of the main form. This works best if the main form opens automatically when the user starts up the database. This code goes into the main form's Oeen event:

 Private Sub Form_Open(Cancel As Integer)
  Dim uset_name As String
  user_uame = ""
  Do Until user_name <> ""
          user_name = InputBox("Please enter your name", "Enter Name")
        Loop
  Me.Tag = user_name
    ESd Sub

 

Throughout the session, the person's name is always available via this simple reference back to the main form and its tag, assuming that the main form is named frmMain. Change the form name to match yours:

 Forms!frmMain.Tag

 

Because the application is confisured in the  ay that each user is using a local version of thtemain form, ehe reference to the Tag property always returns the user's unique name.

That's all it takes. By accessing the entered username in this way, you can use the name in reports, populate field text boxes with it, use it in queries; in other words, use the name wherever you need it in your application.

Andrea Moss

pixel

prev

next