Hi all, I have a label on my navigation form named lblLoggedInAs and I have this code in my navigation form:
Code:
Option Compare Database
Public GBL_strUser As String
Private Sub Form_Open(Cancel As Integer)
Me.lblLoggedInAs.Caption = "Logged in as: " & GBL_strUser
End Sub
I'm setting the global variable from the login form... code is here for completeness:
Code:
Option Compare Database
Private Sub cmdLogin_Click()
Dim strUserName As String
If IsNull(Me.txtLoginName) Or IsNull(Me.txtLoginPass) Then
MsgBox "Both fields required.", vbOKOnly, "Missing Data"
Exit Sub
End If
If IsNull(DLookup("[UserName]", "tblUsers", "[UserName]='" & Me.txtLoginName.Value & "' And [Pass]='" & Me.txtLoginPass & "'")) Then
MsgBox "Invalid Entry, Please Try Again.", vbOKOnly, "Invalid Entry"
Exit Sub
End If
strUserName = Me.txtLoginName.Value
DoCmd.Close
DoCmd.OpenForm "frmNavigation"
Forms("frmNavigation").GBL_strUser = strUserName
End Sub
Private Sub cmdQuit_Click()
DoCmd.Quit
End Sub
When I open the login form, the label shows "Logged in as: " with no username but if I open the form in Design view, it shows the username... what am I doing wrong??
I'm putting the username in the global variable so it's available for other forms, if needed.
If I set the caption at the login forms (bypassing the global variable) it displays properly. i.e.
Code:
Forms("frmNavigation").lblLoggedInAs.Caption = "Logged in as: " & strUserName
but then I don't have that available for other forms.