G
gsnidow via AccessMonster.com
Greetings folks. I have the following code behind the on open event of
several forms.
Dim cn As ADODB.Connection
Dim rsLOGIN_ID As Recordset
Dim strSQL As String
strSQL = "SELECT system_user AS LOGIN_ID, " & _
"u.first_name + ' ' + u.last_name AS USER_NM " & _
"FROM tblusers u " & _
"WHERE u.login_nm = system_user"
Set rsLOGIN_ID = New ADODB.Recordset
Set cn = Application.CurrentProject.Connection
rsLOGIN_ID.Open strSQL, cn, adOpenForwardOnly, adLockOptimistic
Me.txtUser = (rsLOGIN_ID("LOGIN_ID"))
Me.txtUserName = (rsLOGIN_ID("USER_NM"))
The purpose is to populate two unbound text boxes, txtUser and txtUserName,
with their nt login and their name from the database, for use by some
security measures I have in place beyond server security. The problem is
that every time I make a new form I must put this code in it. My question is
this: is there a way I could run this code, or something similar, when the
application is starting, and store the two values somewhere globally
accessible, so I could reference them from any form for the duration of the
session until the user quits the application?
Greg
several forms.
Dim cn As ADODB.Connection
Dim rsLOGIN_ID As Recordset
Dim strSQL As String
strSQL = "SELECT system_user AS LOGIN_ID, " & _
"u.first_name + ' ' + u.last_name AS USER_NM " & _
"FROM tblusers u " & _
"WHERE u.login_nm = system_user"
Set rsLOGIN_ID = New ADODB.Recordset
Set cn = Application.CurrentProject.Connection
rsLOGIN_ID.Open strSQL, cn, adOpenForwardOnly, adLockOptimistic
Me.txtUser = (rsLOGIN_ID("LOGIN_ID"))
Me.txtUserName = (rsLOGIN_ID("USER_NM"))
The purpose is to populate two unbound text boxes, txtUser and txtUserName,
with their nt login and their name from the database, for use by some
security measures I have in place beyond server security. The problem is
that every time I make a new form I must put this code in it. My question is
this: is there a way I could run this code, or something similar, when the
application is starting, and store the two values somewhere globally
accessible, so I could reference them from any form for the duration of the
session until the user quits the application?
Greg