I like to do the same thing. I will store the UserID in an unbound textbox in a form that always remains open. My approach to this is a little complicated. I start by creating a public variable in a general module. This way I have a variable I can pass the UserID from form to form with, regardless of which form the user may be using.
I start by declaring a variable in a general module.
Code:
'Declare variable for UserID
Public glngDeptID As Long
Then I put some code in the logon form. This form will likely be the first form your user sees.
Code:
If Not IsNothing(Me.cmbUserID.Column(0)) Then
glngDeptID = Me.cmbUserID.Column(0)
DoCmd.OpenForm "frmMain", acNormal
DoCmd.Close acForm, "frmSplash"
Else
Exit Sub
End If
Now that the UserID value is in the public variable, I can pass it to the unbound textbox in my frmMain. This form remains open while the application is open. In this form's "Load" event, I place the following.
Code:
If Not IsNull(glngDeptID) Then
Me.txtDeptID.Value = glngDeptID
Else
Me.txtDeptID.Value = ""
End If
Now that the textbox has the UserID/DeptID, I can grab this value from anywhere within my app. I don't have to wory about the variable losing its value. Each time I need to use the UserID, I reassign the variable the UserID value in THAT form's load event, just before I need it.
Code:
If Not IsNull(Forms!frmMain![txtDeptID]) Then
glngDeptID = Forms!frmMain![txtDeptID] 'Remind Access what the DeptID is
Else
glngDeptID = ""
End If
Doing it this way helps in cases your users have a full version of access installed and your program does not shut down in cases of runtime errors. If the variable loses its value it may be helpful to assign it again.