Remember which User is logged in?

wrightyrx7

Registered User.
Local time
Today, 14:10
Joined
Sep 4, 2014
Messages
104
Hi All,

I have a simple Login Form and the following code, for a user to login (obviously if they get the username and password correct).

My database is to log calls, and part of the form that is completed is who took the call.

The person who took the call is the person logged in, how can I get access to remember who is logged in ready for when a new call is taken?

Code:
Private Sub Command1_Click()
    If IsNull(Me.txtLoginID) Then
        MsgBox "Please enter a Login ID", vbInformation, "Login ID Required"
        Me.txtLoginID.SetFocus
    ElseIf IsNull(Me.txtPassword) Then
        MsgBox "Please enter a Password", vbInformation, "Password Required"
        Me.txtPassword.SetFocus
    Else
        If (IsNull(DLookup("[Login ID]", "[Users Extended]", "[Login ID]='" & Me.txtLoginID.Value & "'  and Password='" & Me.txtPassword.Value & "'"))) Then
            MsgBox "Incorrect Login ID or Password."
        Else
            DoCmd.OpenForm "Call Details"
            DoCmd.Close acForm, "Login", acSaveNo
        End If
    End If
End Sub
 
Add an extra field to the Call Logs table (or a relevant table) for this.
 
I already have a field in my Call Log table, im just wondering how to tell that field who is logged in when the call is taken.
 
I don't understand your question. You already have the value in txtLoginID, if it's the credentials were entered successfully isn't it a simple matter of getting the value from the txtLoginID textbox and saving it in the respective field in the Call Log table?
 
Sorry... I mean because there maybe many users.

But from what your saying, I think I know what you mean.

When the user logs in, close the "Login" form but keep the username in the Textbox to refer to?

Then maybe have a action that clears the Textbox the next time it runs ready for the next user?
 
Yes, something like that. But the textbox doesn't need to be cleared, next time it opens it will be blank. Get the corresponding Log ID from the DLookup, save it to a variable, once the Call Log form is opened, pass that variable value to the LogID field.

Isn't it supposed to be a multi-user database with each user with their own front end?

By the way, I haven't yet looked at your db on your other thread. I'll get to it later.
 
Yes once complete I will split it so each user has their own front end of it.

I have added the below to my vba code, but stuck on what to do with it next. (sorry to be a pain, its nothing like excels vba :(

Code:
Option Compare Database
Option Explicit
[COLOR="Red"]Dim cUser As String[/COLOR]
Private Sub Command1_Click()
    If IsNull(Me.txtLoginID) Then
        MsgBox "Please enter a Login ID", vbInformation, "Login ID Required"
        Me.txtLoginID.SetFocus
    ElseIf IsNull(Me.txtPassword) Then
        MsgBox "Please enter a Password", vbInformation, "Password Required"
        Me.txtPassword.SetFocus
    Else
        If (IsNull(DLookup("[Login ID]", "[Users Extended]", "[Login ID]='" & Me.txtLoginID.Value & "'  and Password='" & Me.txtPassword.Value & "'"))) Then
            MsgBox "Incorrect Login ID or Password."
        Else
            [COLOR="red"]cUser = DLookup("[Username]", "[Users Extended]", "[Login ID]='" & Me.txtLoginID.Value & "'")[/COLOR]
            DoCmd.OpenForm "Call Details"
            DoCmd.Close acForm, "Login", acSaveNo
        End If
    End If
End Sub
 
Last edited:
Scope of a variable.

Put this in a Module (not a Class Module, just a Module):
Code:
Public cUser As String
 

Users who are viewing this thread

Back
Top Bottom