Capture NT username for form

G

Guest

I've got a database created using SQL tables for data storage. The data
entry form is the only thing users see when they open the database -- I've
removed all menus and toolbars, hidden the database window, put the main form
as the Display Form. All users use the same locked-down SQL login and
password to access the data.

What I would like to do is pull the NT Username and store it in the table
for user-level accountability. I can validate the username in vb to allow
access to other forms and controls using an event procedure and the vb below:

Dim LoggedUser As String
LoggedUser = VBA.Interaction.Environ("USERNAME")

I need to be able to pull this same username (their network login name) and
store it on the record they are entering. Even if it has to be created in a
field on the form, that's no problem, I'll just hide it.

Thanks for any ideas!
 
K

Keith

Caffe said:
I've got a database created using SQL tables for data storage. The data
entry form is the only thing users see when they open the database -- I've
removed all menus and toolbars, hidden the database window, put the main
form
as the Display Form. All users use the same locked-down SQL login and
password to access the data.

What I would like to do is pull the NT Username and store it in the table
for user-level accountability. I can validate the username in vb to allow
access to other forms and controls using an event procedure and the vb
below:

Dim LoggedUser As String
LoggedUser = VBA.Interaction.Environ("USERNAME")

I need to be able to pull this same username (their network login name)
and
store it on the record they are entering. Even if it has to be created in
a
field on the form, that's no problem, I'll just hide it.
This isn't really a security issue, you might be better off posting to
comp.databases.ms-access, but in a nutshell you need to programmatically
open a recordset and store LoggedUser in the field of your choice.

Here's an example which adds a new record to an audit table:

Dim db As Database
Dim rs As Recordset
Dim strSQL As String

Set db = CurrentDb

strSQL = "SELECT qtblLog.* FROM qtblLog;"
Set rs = db.OpenRecordset(strSQL)

With rs
.AddNew
!UserName = libUserName()
!fldCurrentUser = CurrentUser
!computername = Environ("COMPUTERNAME")
!LogIn = Now()
.Update
.Bookmark = .LastModified
glngLogID = !logid
.Close
End With
Set rs = Nothing
Set db = Nothing

THE FOLLOWING CODE IS IN A LIBRARY MODULE:

Public Function libUserName() As String
' Returns the Username defined by the environment variable USERNAME
' otherwise returns the current Access user

On Error Resume Next

Dim strUserName As String

strUserName = Environ("USERNAME")
If strUserName = "" Then
strUserName = CurrentUser()
End If
libUserName = strUserName
End Function

Regards,
Keith.
www.keithwilby.com
 
J

Jeff Conrad

in message:
I've got a database created using SQL tables for data storage. The data
entry form is the only thing users see when they open the database -- I've
removed all menus and toolbars, hidden the database window, put the main form
as the Display Form. All users use the same locked-down SQL login and
password to access the data.

What I would like to do is pull the NT Username and store it in the table
for user-level accountability. I can validate the username in vb to allow
access to other forms and controls using an event procedure and the vb below:

Dim LoggedUser As String
LoggedUser = VBA.Interaction.Environ("USERNAME")

I need to be able to pull this same username (their network login name) and
store it on the record they are entering. Even if it has to be created in a
field on the form, that's no problem, I'll just hide it.

I believe you need this:

http://www.mvps.org/access/api/api0008.htm

You can also get the computer name if you need it as well:

http://www.mvps.org/access/api/api0009.htm
 

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