Originally Posted by
Micron
Very easy. Look up fosUserName. I can't recall if you need to worry about 32 vs 64 bit or not - it depends on the API calls.
There is not much you can do about a user "pulling the plug". My suggestion would be to post a db copy with some scenarios that you know/think cause issues. I suppose we could review all the posts to see what they are, but a summary would be nice. See "how to attach files" at the top of the forum window if you're not familiar with the requirements.
Just found out something interesting.
So like mentioned before, if I open the application and the login form loads and I don't type in any credentials and close the application by right clicking and closing Access by the taskbar, it will save a blank record. However, if I type in credentials and actually login then close the app by taskbar, it will of course show the login date and time but it also saved the logout date and time as well. Why is it saving the logout date and time only if I login successfully as opposed to not logging in? Here is the code I have in the Login button click event and the On Unload event for the login form:
Code:
Private Sub cmdLogin_Click()
Dim validCredentials As IntegerDim userLevel As Variant
Dim ID As Integer
validCredentials = DCount("Username", "[tblUser]", "[Username] ='" & txtUsername & "' AND [Password]='" & txtPassword & "'")
ID = DLookup("UserID", "tblUser", "Username = '" & Me.txtUsername.Value & "'")
If validCredentials = 1 Then
userLevel = Nz(DLookup("UserSecurity", "[tblUser]", "[Username]='" & txtUsername & "'"), 0)
If userLevel = "Admin" Then
Me.txtLoginDateTime.Value = Now()
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm "Login", acNormal, , , acFormEdit, acHidden
DoCmd.OpenForm "Main Menu_admin"
Else
Me.txtLoginDateTime.Value = Now()
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm "Splash Screen Load"
End If
Else
MsgBox "Invalid Username Or Password!", vbExclamation, "UNAUTHORIZED!"
Me.txtPassword.SetFocus
End If
End Sub
Code:
Private Sub Form_Unload(Cancel As Integer)
If Me.Dirty Then
Me.Undo
Exit Sub
End If
If IsNull(Me.txtUsername) Or IsNull(Me.txtPassword) Then
Exit Sub
Else
[Forms]![Login]![txtLogoutDateTime] = Now()
End If
End Sub