Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2012
    Posts
    2

    Audit Issue

    Hi,

    i am trying to record the current windows username in an audit field. But all i can get is the Username Admin? any ideas?



    Dim MyForm As Form, C As Control, xName As String
    Set MyForm = Screen.ActiveForm






    'Set date and current user if form has been updated.
    MyForm!Audit = MyForm!Audit & Chr(13) & Chr(10) & _
    "Changes made on " & Now & Date & " by " & CurrentUser() & ";"


    'If new record, record it in audit trail and exit sub.
    If MyForm.NewRecord = True Then


    MyForm!Audit = MyForm!Audit & Chr(13) & Chr(10) & _
    "New Record """
    End If


    'Check each data entry control for change and record
    'old value of Control.
    For Each C In MyForm.Controls

    'Only check data entry type controls.
    Select Case C.ControlType
    Case acTextBox, acComboBox, acListBox, acOptionGroup
    ' Skip Audit field.
    If C.Name <> "Audit" Then

    ' If control was previously Null, record "previous
    ' value was blank."
    If IsNull(C.OldValue) Or C.OldValue = "" Then
    MyForm!Audit = MyForm!Audit & Chr(13) & _
    Chr(10) & C.Name & "--previous value was blank"

    ' If control had previous value, record previous value.
    ElseIf IIf(IsNull(C.Value), "", C.Value) <> C.OldValue Then
    MyForm!Audit = MyForm!Audit & Chr(13) & Chr(10) & _
    C.Name & "==previous value was " & C.OldValue
    End If
    End If
    End Select
    Next C


    TryNextC:
    Exit Function

    Err_Handler:
    If Err.Number <> 64535 Then
    MsgBox "Error #: " & Err.Number & vbCrLf & "Description: " & Err.Description
    End If
    Resume TryNextC
    End Function

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    That method only works with Access security. You can use the Environ() function orhttp://access.mvps.org/access/api/api0008.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Join Date
    Jun 2012
    Posts
    2
    Quote Originally Posted by pbaldy View Post
    That method only works with Access security. You can use the Environ() function orhttp://access.mvps.org/access/api/api0008.htm
    so do i just substitute the currentUser() for Environ()?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Yes, though you need the appropriate argument for Environ().
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Audit Log
    By Darkladymelz in forum Programming
    Replies: 15
    Last Post: 03-06-2012, 11:36 AM
  2. Audit Trail
    By bigroo in forum Programming
    Replies: 4
    Last Post: 02-22-2012, 07:55 PM
  3. audit trail
    By slimjen in forum Forms
    Replies: 1
    Last Post: 10-13-2011, 01:52 PM
  4. audit Log
    By mwabbe in forum Access
    Replies: 42
    Last Post: 05-30-2011, 07:23 AM
  5. Audit trail question
    By jpkeller55 in forum Access
    Replies: 5
    Last Post: 09-13-2010, 04:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums