• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 65
  • Last Modified:

Environ()

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

Sir,
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.
Regards,
Kamlesh Jain
0
Kamlesh Jain
Asked:
Kamlesh Jain
2 Solutions
 
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

0
 
Dale FyeCommented:
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
0
 
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now