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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update textbox with username 1

Status
Not open for further replies.

newestAF

Technical User
Jul 9, 2009
72
US
I got a code from another dbs that sort of does what I need. I can't get it to work though. Here it is:

*************START CODE********************
Option Compare Database
'windows-defined type
Private Type SYSTEM_INFO
dwOemID As Long
End Type

Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Type ComputerUserInfo
username As String
ComputerName As String
End Type

Private Sub GetUserInfo(CUI As ComputerUserInfo)

Dim r&, ret$

'get the user's name
ret$ = Space$(256)
r& = GetUserName(ret$, Len(ret$))
CUI.username = StripNull$(ret$)

'get the computers's name
ret$ = Space$(256)
r& = GetComputerName(ret$, Len(ret$))
CUI.ComputerName = StripNull$(ret$)

End Sub


Private Sub DisplayResults(CUI As ComputerUserInfo)
'fill in the labels


' Label1 = "User Name :"
' Label1 = "Computer Name :"

'show the info
'Computer User Info and Windows Registry Info
Text1 = CUI.username
Text2 = CUI.ComputerName

End Sub

Private Function StripNull$(item$)

On Local Error Resume Next
StripNull$ = Left$(item$, InStr(item$, Chr$(0)) - 1)

End Function

Private Sub Command43_Click()
On Error GoTo ITF_Macro_Err
Dim CUI As ComputerUserInfo
'Dim db As DAO.Database
'Dim rst As DAO.Recordset
Dim stLastUp As String
'Dim stSSAN as String
'stSSAN = Me.SSAN.Value
'Set db = CurrentDb
'Set rst = db.OpenRecordset("SELECT * FROM [Query1] WHERE [SSAN] = stSSAN;")
'rst.MoveFirst

With Me.Text67

.Value = CUI.username
End With

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenQuery "Exit Refresh", acViewNormal, acEdit
DoCmd.Close acForm, "Individual Tracking Form"
DoCmd.OpenForm "Main Menu", acNormal

ITF_Macro_Exit:
Exit Sub

ITF_Macro_Err:
DoCmd.Close acForm, "Individual Tracking Form"
Resume ITF_Macro_Exit

End Sub

*******************END CODE***********************

I have a textbox on the Individual Tracking Form that I need to automatically update once data has been saved to the record. I want it to reflect the name of the user who made the last update. I know I ask a lot of questions but I have to learn somewhere if I can find the answer. Thanks in advance.
 
You may try simply this:
Me!Text67 = Environ("USERNAME")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Can't believe it was that simple. Now I have added the date in there but not sure how to change the format from mm/dd/yyyy to dd-mmm-yyyy.
 
Format(Date(), "dd-mmm-yyyy")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
One last question. How do I get it to leave the username textbox alone if no change is made to the record?
 
If Me.Dirty Then
Me!Text67 = Environ("USERNAME")
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top