I'll just assume you're loading usernames and passwords from a table since you didn't specify.
Once the user has logged in you can store their username in a public variable in a module.
Then you just need to create a public function to read that variable.
Public LoggedInUser As String
Public Function GetUserName() As String
GetUserName = LoggedInUser
'or to get windows login use
'GetUserName = CreateObject("WScript.Network").UserName
End Function
You can use public functions pretty much anywhere, macros, queries, etc.
For a textbox just set the control source to =GetUserName()
I'll also assume you're asking for help with the data loading...
This example requires two text boxes, txtUser and txtPW.
When the form opens, keypreview is set to true, which means that whenever the user presses a button the form gets to process the event before the control. I've used it here to trap the Return key which has a keycode of 13.
Whenever the user presses the return key, CheckPW checks that neither text box is empty then opens a recordset to get the password from a table called 'user'.
It then does a case sensitive check against both passwords. If they match, CheckPW is set to true, the user is logged in and the public username variable is set.
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 13
If CheckPW(Trim("" & txtUser), Trim("" & txtPW)) Then
LoggedInUser = Trim("" & txtUser)
DoCmd.OpenForm "WrittenStatsForm"
DoCmd.Close acForm, Me.Name
End If
End Select
End Sub
Private Function CheckPW(usr As String, pw As String) As Boolean
If usr = "" Then Exit Function
If pw = "" Then Exit Function
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim retval As String
Set db = CurrentDb
Set rs = db.OpenRecordset("select pw from user where username='" & usr & "'")
If Not rs.EOF Then retval = rs("pw").Value
rs.Close
Set rs = Nothing
Set db = Nothing
CheckPW = StrComp(retval, pw, vbBinaryCompare) = 0
End Function