created by field

  • Thread starter Thread starter Scott
  • Start date Start date
S

Scott

I had a field named created by that would pull in the network user name, then
date and time record was created as shown below:

sbingaman 12/27/2007 7:42:15 AM

what do i need to do to get this to repopulate automatically again? i can't
seem to find the same post that helped me create it.

Thanks.
 
Scott

First things first...

When you stuff more than one fact in a single field, you make more work for
yourself, for Access and for anyone who tries to maintain/understand your
database.

Instead of using a single text field, consider two fields:
[CreatedBy] (network user name)
[CreatedDate] (date/time)

With this approach, you can (much more easily) find all the records created
on a given date (or by a specific user).

You might even want to consider adding:
[LastUpdatedBy]
and
[LastUpdated]
fields.

You can control what goes into these by setting their values in code behind
the form's BeforeUpdate event (which is also a good place/time to do your
validation).

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Option Explicit
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function GetUserName() 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
GetUserName = Left$(strUserName, lngLen - 1)
Else
GetUserName = vbNullString
End If
End Function

' -==== End of Module ===

I'm not sure what happened, but i need to get these fields to populate. I
also added the lastupdatedby and lastupdated fields.

Thanks for all your help.

Scott

Jeff,

I added the fields you suggested. I'm just having a hard time writing the
code to get them to get to update with windows user name, etc...

I'm using the following code in a module, that i need to transfer over:



Jeff Boyce said:
Scott

First things first...

When you stuff more than one fact in a single field, you make more work for
yourself, for Access and for anyone who tries to maintain/understand your
database.

Instead of using a single text field, consider two fields:
[CreatedBy] (network user name)
[CreatedDate] (date/time)

With this approach, you can (much more easily) find all the records created
on a given date (or by a specific user).

You might even want to consider adding:
[LastUpdatedBy]
and
[LastUpdated]
fields.

You can control what goes into these by setting their values in code behind
the form's BeforeUpdate event (which is also a good place/time to do your
validation).

Regards

Jeff Boyce
Microsoft Office/Access MVP

Scott said:
I had a field named created by that would pull in the network user name,
then
date and time record was created as shown below:

sbingaman 12/27/2007 7:42:15 AM

what do i need to do to get this to repopulate automatically again? i
can't
seem to find the same post that helped me create it.

Thanks.
 
Back
Top