Results 1 to 8 of 8
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Storing last modified (97)

    I have a field to store the date and time a record was last modified. I'm trying to use the After Update event for a form to set the value of this field to Now(), but I'm getting stuck in the form!! It won't allow to move to the next record. Help?!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Storing last modified (97)

    Use the BeforeUpdate event instead...

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Storing last modified (97)

    Dur!! So obvious.. Thanks much!

  4. #4
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Storing last modified (97)

    Oops! Not quite there yet.. It doesn't work on the BeforeUpdate event of the form! Do you mean for all the individual fields?

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Storing last modified (97)

    ...Ignore me! It's working perfectly. Thanks again.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Storing last modified (97)

    I often use the BeforeUpdate event of a form (not of individual controls) to do this. Here is an actual example from one of my databases:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    ModificationDate = Date
    ModifiedBy = NetUser
    End Sub

    NetUser is a custom function that returns the network login name of the user.

  7. #7
    Lounger
    Join Date
    Jul 2002
    Location
    Indianapolis, Indiana
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Storing last modified (97)

    Hans, could you post the NetUser function, and show how one would use it?

    Thanks!!

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Storing last modified (97)

    Hi Bob,

    The NetUser function uses the Windows API function WNetGetUserA to retrieve the network login name of the current user. Please note that this is different from the Access login name. You can use NetUser just as you would use any other function - in expressions and in code. The sample code in my reply higher up in this thread uses it to set the name of the user who last modified a record. Another use could be to display the login name on a form or report - place a text box, for instance in the header or footer section, with control source =NetUser().

    Here is the code. If you put it in a general module, it will be available throughout the database. The first bit must go in the declaration section of the module, at the top.

    <img src=/w3timages/blueline.gif width=33% height=2>

    Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
    (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long

    Public Function NetUser() As String
    Dim strName As String, strUserName As String
    strName = vbNullString
    strUserName = Space(255)
    If WNetGetUser(strName, strUserName, Len(strUserName)) = 0 Then
    NetUser = Left(strUserName, InStr(strUserName, vbNullChar) - 1)
    Else
    NetUser = "-unknown-"
    End If
    End Function

    <img src=/w3timages/blueline.gif width=33% height=2>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •