I had this question after viewing Environ("USERNAME").

I want to store username and date/Time stamp in each record, for 3 tables.

I am using below same codes for three forms ( BeforUpdate Event)

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me!updateBy = Environ("username")
Me!updateTime = Now()
End Sub

However, in one form, the [updateBy] field and [updateTime] fields are saved, but in two forms its not saved.
Its shows error as Field updateby is not found..
What can be the cause ?
Would appreciate help.
Thanks in advance.
Kamlesh Jain
Kamlesh JainManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
This simply means, that the column updateBy  does not exist in this form's record source.

btw, you should use Win API, cause Environ() calls like this can be easily spoofed.

Option Compare Database
Option Explicit

Private Declare Function GetUserNameA Lib "AdvApi32" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function GetUserName() As String

  Const BUFFER_SIZE As Long = 100

  Dim Buffer As String
  Dim Result As Long
  Dim Size As Long

  Buffer = String(BUFFER_SIZE + 1, 0)
  Size = BUFFER_SIZE + 1
  Result = GetUserNameA(Buffer, Size)
  If Result <> 0 Then
    GetUserName = Left(Buffer, Size - 1)
  End If

End Function

Open in new window

Dale FyeOwner, Developing Solutions LLCCommented:
I assume that you are using a query for the record source for these other two forms, and failed to include those two fields in the query.

You might also want to reconsider use of the Environ( ) function as this can be overwritten and will not necessarily contain the Windows UserID of the person currently logged on.  Instead, use the fOSUsername function found here

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kamlesh JainManagerAuthor Commented:
Hello. Thanks for the reply. It was a silly mistake from my end. Hope sharing of points is justified.... :)
Best Regards,
Kamlesh Jain
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.