PC Review


Reply
Thread Tools Rate Thread

Capture NT username for form

 
 
=?Utf-8?B?Q2FmZmU=?=
Guest
Posts: n/a
 
      2nd Jun 2005
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!


 
Reply With Quote
 
 
 
 
Keith
Guest
Posts: n/a
 
      2nd Jun 2005
"Caffe" <(E-Mail Removed)> wrote in message
news:C4E225D5-F35D-4E8C-B6B9-(E-Mail Removed)...
> 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


 
Reply With Quote
 
Jeff Conrad
Guest
Posts: n/a
 
      2nd Jun 2005
"Caffe" wrote in message:
news:C4E225D5-F35D-4E8C-B6B9-(E-Mail Removed)...

> 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

--
Jeff Conrad
Access Junkie
Bend, Oregon


 
Reply With Quote
 
=?Utf-8?B?Q2FmZmU=?=
Guest
Posts: n/a
 
      2nd Jun 2005
Got it.... thanks, guys!


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Capture NT username AndrewB Microsoft Access Security 4 19th Dec 2008 11:01 PM
Capture UserName =?Utf-8?B?Um9lQ2FzdGxl?= Microsoft Access VBA Modules 1 26th Jan 2007 04:09 PM
capture username() on form =?Utf-8?B?YmFicw==?= Microsoft Access Security 4 4th May 2006 05:50 PM
Inability to Capture Username Henry Stockbridge Microsoft Excel Programming 5 20th Feb 2006 09:30 PM
Capture UserName for Log Terry Microsoft Access Security 2 25th Aug 2003 04:59 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:59 PM.