Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing data to table

Status
Not open for further replies.

ptrifile

Technical User
Aug 10, 2004
457
US
I have created the following module to populate a form with the users windows login name:

Code:
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

and in the form i have an unbound text box with an event which populates the text box:

Code:
User = fOSUserName()
Me.txtusername = Nz(User, "")


I need to be able to have the "windows username" of the person entering the data written to a table but I cannot figure out how to accomplish that...when i change the unbound text box to a bound it gives me an error...can anyone give me any suggestions.

thanks!

Paul
 
In the BeforeUpdate event procedure of the form:
Me![name of bound user control] = fOSUserName

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Try,
Dim Uname As String
Uname = Environ("USERNAME")
Me.txtusername = Uname
 
Im sure PHVs suggestion will work but something to consider - store the user name once in a global variable on startup (just call the function from your autoexec) - it will save your code calling the function for every record a user adds.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top