Link to home
Start Free TrialLog in
Avatar of BOEING39
BOEING39

asked on

UPDATED TIME STAMP MS ACCESS

I need to incoprorate an update function in my access data base anytime an individual record is modified.   It will require time and date.   Any suggestions?
SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In an Access table Jim uses Now() rather than GetDate()  (which only works in SQL Server).
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Both of the above comments are correct.

Also, fyi, below is the function (although somewhat old) to get the Windows login user

Put this in the declaraction section of any code module

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Open in new window


Then add this function

Public Function fn_get_user_name() As String

'Returns the network ID of the person that logged into the machine that is running this Access application:
'This is not the same as the Access security user.

'Visual Basic Source Code Library, The Waite group, Chapter 12.5

On Error GoTo err_fn_get_user_name

Dim str_user_name As String, lng_buffer_size As Long, lng_ret_code As Long, lng_null_character_position As Long

str_user_name = Space(80)
lng_buffer_size = Len(str_user_name)

lng_ret_code = GetUserName(str_user_name, lng_buffer_size)

lng_null_character_position = InStr(str_user_name, Chr(0))
If lng_null_character_position > 0 Then
    str_user_name = Left(str_user_name, lng_null_character_position - 1)
Else
    str_user_name = " "
End If

fn_get_user_name = UCase(str_user_name)

exit_fn_get_user_name:
    Exit Function
    
err_fn_get_user_name:
    fn_get_user_name = "Not able to get user name."
    Resume exit_fn_get_user_name
    
End Function

Open in new window


Then building off of fyed's code above, also set txt_modified_by in the BeforeUpdate event.
Also add a BeforeInsert block, and set txt_created_by with ... me.txt_created_by = fn_get_user_name.
No points wanted...

In case your concern is "Auditing", ...see these popular links:
http://support.microsoft.com/kb/197592
http://allenbrowne.com/appaudit.html
Avatar of BOEING39
BOEING39

ASKER

Thx everyone for the responses.   Ok I created a new column in my Data base "DatetimeMod" which is where I want to store the date time stamp @ update and set the default value to "Now().    This particular page is a Details view that is hyperlinked off my main page.   Can someone advise on the placement of the above code on the attached "Home3.aspx".  


I did not use code behind on this page as it is just a details page.
Home3.aspx
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The two responses listed were closest answers too the category I selected.   Moving question to C# as I need assistance with code behind to fully resolve.