Using Windows Login

A

Anthony Bollinger

Is there a way to use the Windows login credentials/user to apply Access
2003 security without the need for a separate login? All we need to be sure
of is that the user is valid/expected. It is not necessary to have a
separate login if we can take advantage of the already valid user login to
Windows. How is this accomplished?

Thanks,
Tony
 
J

Joan Wild

If all you want to do is ensure that the user is valid/expected, why not just put the database in a folder, and use the folder permissions to allow only those users?
 
A

Anthony Bollinger

Joan Wild said:
If all you want to do is ensure that the user is valid/expected,
why not just put the database in a folder, and use the folder
permissions to allow only those users?

Okay, I can see where I was very unclear. We do want to use Access
permissions for different users (3 groups), but I was wondering if there is
a way to do this based on the Windows login and not need to create separate
user/login information for Access. Has anyone implemented something like
this?

Many thanks,
Tony
 
R

Rocky

=Environ("USERNAME") takes the user name from windows. or it may be without
the " ", I can't remember. My database is on the network at work. I will
look at it tomorrow and let you know for sure.
 
R

Rocky

This is how I did it. First, I created a table with a name like of LeadTech,
since that was the access level I wanted. I inputed my user ID into this
table as a record, and any other user who needed this "higher" access. So in
this case, my login ID is Rocky.Bolin

On the form, in VB, I did the following.

Private Sub Form_Activate()
DoCmd.Restore
On Error Resume Next
Dim rst As Recordset, strString As String, tempstring As String
UserName = Environ("USERNAME")

Me.Filter = "UserName = '" & Environ("USERNAME") & "'"
Me.FilterOn = True
End Sub



// The Environ("USERNAME") takes your windows login ID. Remember it!


Then, to gain access to the higher level form, on the button to goto the
form, I did this.


Private Sub Label2_Click()
Dim rst As Recordset, x As String
Set rst = CurrentDb.OpenRecordset("select * FROM LeadTech WHERE UserName =
'" & Environ("USERNAME") & "'", dbOpenDynaset)
If Not rst.EOF Then
If rst!UserName = Environ("USERNAME") Then
x = MsgBox("Access granted for '" & Environ("USERNAME"))
DoCmd.OpenForm "Tool_Requests", acNormal


'Me.Visible = False
Exit Sub
End If
End If
rst.Close


x = MsgBox("Not a Lead Tech. Access Denied.")

End Sub



// These commands look up the record in table LeadTech, where I added my
username. If I use someone not in the table, it tells me "Not a lead tech.
Access Denied."
 
D

Douglas J. Steele

I always cringe when people suggest using an environment variable for this
purpose, given how easy it is to reset an environment variable.

All that's necessary is to open a DOS box, use the SET command to set the
USERNAME variable to whatever you want, then open Access using a command
line in that same DOS box. While the USERNAME isn't actually reset, it is
for the duration of that DOS box, so Access will see whatever the user tells
it to see.

Far safer, in my opinion, is to use the GetUserName API call. See
http://www.mvps.org/access/api/api0008.htm at "The Access Web" for a
complete sample.
 
A

Anthony Bollinger

Thanks Rocky and Doug! I will check out what is possible with these
options. --Tony
 

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