charlie442
Registered User.
- Local time
- Today, 01:35
- Joined
- Jan 14, 2011
- Messages
- 53
Hi
I have written a database which creates TempVars for users when they login based on tblUsers. I now want to be able to call on this tempvar when, for example, a user completes a case or enters a comment on a particular case. The code used in the login form is as follows:
Say now I have a subform which shows comment history on a case. How do I include a user field which shows who filed tht comment. This may be fairly straight forward but to be honest I am a bit of a hack at this.
Any help appreciated
I have written a database which creates TempVars for users when they login based on tblUsers. I now want to be able to call on this tempvar when, for example, a user completes a case or enters a comment on a particular case. The code used in the login form is as follows:
Code:
Private Sub cmdLogin_Click()
Dim bValid As Boolean
bValid = False
'Check to make sure that username and password are not blank
If Nz(Me.txtUserName, "") = "" Then
MsgBox "User Name cannot be blank."
Me.txtUserName.SetFocus
ElseIf Nz(Me.txtPassword, "") = "" Then
MsgBox "Password cannot be blank."
Me.txtPassword.SetFocus
Else
'If the username is incorrect we'll tell the user that they entered an invalid username or password
'It's generally considered an insecure practice to inform the user that they have entered a
'correct or incorrect username.
If DCount("UserName", "tblUser", "UserName = '" & Replace(Me.txtUserName, "'", "''") & "'") = 0 Then
MsgBox "Sorry, you entered an invalid username or password."
Else
Dim sPswdHash As String
sPswdHash = Hash(Me.txtPassword)
If DLookup("PswdHash", "tblUser", "UserName = '" & Replace(Me.txtUserName, "'", "''") & "'") <> sPswdHash Then
MsgBox "Sorry, you entered an invalid username or password."
Else
bValid = True
'TempVars is only available in Access 2007 and Access 2010
'Change this to use a global variable if you are using Access 2003 or older
'Global variables do not survive resets while TempVars do
'Storing the UserID is what determines if a user is logged in as well as
'which user is logged in.
TempVars.Add "UserID", DLookup("UserID", "tblUser", "UserName = '" & Replace(Me.txtUserName, "'", "''") & "'")
End If
End If
End If
If bValid = True Then
'Open the main form.
DoCmd.OpenForm "Frm_Main_Switchboard"
'Close this form
DoCmd.Close acForm, "frmLogin"
Else
Me.txtUserName = Null
Me.txtPassword = Null
Me.txtUserName.SetFocus
End If
End Sub
Say now I have a subform which shows comment history on a case. How do I include a user field which shows who filed tht comment. This may be fairly straight forward but to be honest I am a bit of a hack at this.
Any help appreciated