Re: Using Windows Login



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.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Rocky" <rocco81b@xxxxxxx> wrote in message
news:FFACC60D-627B-4A4B-B597-D6261725AAA8@xxxxxxxxxxxxxxxx
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."

--------------------------------------------------
From: "Rocky" <rocco1981@xxxxxxxxxxx>
Sent: Monday, November 19, 2007 7:57 PM
Newsgroups: microsoft.public.access.security
Subject: Re: Using Windows Login

=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.

"Anthony Bollinger" <tonyb@xxxxxxxxxxxxxxx> wrote in message
news:eTrWtPGKIHA.5224@xxxxxxxxxxxxxxxxxxxxxxx
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



.