"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