Hi all
Need assistance please.
Access 2013
I would like to add a date and user stamp to when a record is new and also modified from a form which would intern update the table.
The code for the module for the user name is as follows;
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
The before Update/insert on the form is as follows in the event procedure;
Option Compare Database
Option Explicit
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
[User ID] = fOSUserName
End If
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
[DateUpdated] = Now
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
[DateModified] = Now
End Sub
When the code is only used on the date modifications every thing works ok. However, my code must be incorrect for the user name stamp.
Any help would be amazing!
Need assistance please.

Access 2013
I would like to add a date and user stamp to when a record is new and also modified from a form which would intern update the table.
The code for the module for the user name is as follows;
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function
The before Update/insert on the form is as follows in the event procedure;
Option Compare Database
Option Explicit
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
[User ID] = fOSUserName
End If
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
[DateUpdated] = Now
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
[DateModified] = Now
End Sub
When the code is only used on the date modifications every thing works ok. However, my code must be incorrect for the user name stamp.
Any help would be amazing!