Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 30th, 2008, 11:42 AM
Authorized User
 
Join Date: Mar 2008
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default CurrentUser()

I am trying to capture record changes and am using CurrentUser() to update a field when the record is changed. It seems that the current user is Admin, no matter who is logged in. What do I need to use to capture who is actually logged into the computer?

 
Old September 30th, 2008, 03:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Are you using a home computer, in a small business with one or two unnetworked computers, or a place where you have a Local Area Network (LAN)?

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old September 30th, 2008, 03:57 PM
Authorized User
 
Join Date: Mar 2008
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes we are on a LAN.

 
Old September 30th, 2008, 03:59 PM
Authorized User
 
Join Date: Mar 2008
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am actually just using a macro to set the value for 3 fields

[Modby]
[ModDate]
[ModTime]

Looking at it as if it were a module:

Code:
Function LastModified()
On Error GoTo LastModified_Err

    With CodeContextObject
        .ModDate = Date()
        .ModTime = Time()
        .ModBy = CurrentUser()
    End With


LastModified_Exit:
    Exit Function

LastModified_Err:
    MsgBox Error$
    Resume LastModified_Exit

End Function
It works well, except that I get "Admin" as the current user all of the time. What should I use to get the network current user??
 
Old October 15th, 2008, 02:09 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Access is not very good at capturing user creds. I put a hidden field on the form called WhoMod (text), and one called DateMod (date) then do this:

Sub FormName_BeforeUpdate

Dim sUser As String
Dim dtDate As Date

dtDate = Now()
sUser = (Environ$("Username"))

Me.DateMod = dtDate
Me.WhoMod = sUser

End Sub

Did that help?

P.S. What's a macro? =)

mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old October 15th, 2008, 02:34 PM
Authorized User
 
Join Date: Mar 2008
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I should have posted this earlier, but, here is how I fixed the problem.
I replaced CurrentUser()
with this.

GetNetworkUserName()

And it worked!

I was suprised, but happy.:D






Similar Threads
Thread Thread Starter Forum Replies Last Post
stored proc --set by currentUser ? reidcor BOOK: ASP.NET Website Programming Problem-Design-Solution 6 August 9th, 2004 05:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.