Tracking Different Users

Tezcatlipoca

Registered User.
Local time
Today, 06:33
Joined
Mar 13, 2003
Messages
246
Hi all,

Right, I'm currently in the early stages of building a multi-user database. My login code works perfectly, allowing me to setup as many users as I want in a table, plus passwords, and have those users login...

...what I have yet to get, and am having trouble with, is the ability to pass the username and password the user enters into the initial form into other forms.

Take a look at my example. there are two users; Quixote and Panza. Both passwords are currently set to 'password'. When the right password is entered, the login form opens the main form. At the moment, the main form consists of nothinfg but a simple text box, and this is the problem area.

Basically, I want a situation where that textbox on the frmMain form is filled out with whatever username the user sucessfully logged in with in the frm Logon form. So Quixote logs in, the box on frm Main should show 'Quixote'; you get the idea.

Can anyone suggest how I can achieve this?
 

Attachments

Pass the Username value to the form using the Openargs parameter of OpenForms. See Access/VBA help for more info.
 
Pass the Username value to the form using the Openargs parameter of OpenForms. See Access/VBA help for more info.

My thinking was along this line, but I posted as I can't seem to track it down in the help. Irritatingly, I'm confident this is a simple answer; I just can't seem to find it! Any pointers you can give would be greatly appreciated!
 
It's quite simple. Whatever you put into the OpenArgs parameter ofOpenForms you can access in the On-Open event of the form using Me.OpenArgs
 
It's quite simple. Whatever you put into the OpenArgs parameter ofOpenForms you can access in the On-Open event of the form using Me.OpenArgs

I got you there, and use OpenForm VB commands myself with a lot of my databases, including this one. My issue is that as soon as the database is opened, frmLogon is opneed where the user gives their username and password. Once they click the 'Logon' button (and assuming their details are fine), frmLogon closes and frmMain opens.

What I'm having trouble with is getting frmLogon to pass that information over to frmMain, since the two forms are never open at the same time, and - given the nature of the database - shouldn't be.

I don't know if it makes a difference, but this database will also have all of its forms opening as modal popups.

I know the answer is simple; I just cannot get the thing to work, or see why it isn't functioning properly!
 
What you need to do in the on click event for the login button is to have a variable strUserName or similar. Populate this when you check the password is valid and then pass it as the openargs param to your Openform command.
 
Hi

Here is the code for the on_click event of the Login Button

Code:
Private Sub cmdLogin_Click()
    Dim strUserName As String
    If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
            MsgBox "User Name cannot be blank", vbOKOnly, "Required Data"
            Me.cboEmployee.SetFocus
        Exit Sub
    End If
    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
            MsgBox "Password cannot be blank", vbOKOnly, "Required Data"
            Me.txtPassword.SetFocus
        Exit Sub
    End If
    If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
        strUserName = DLookup("strEmpname", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value)
        lngMyEmpID = Me.cboEmployee.Value
        
        DoCmd.Close acForm, "frmLogon", acSaveN
        DoCmd.OpenForm "frmMain", , , , , , strUserName
        Else
        MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If
    
    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts > 3 Then
        MsgBox "You do not have access to this database.  Please contact your system administrator.", vbCritical, "Restricted Access!"
        Application.Quit
    End If
    
End Sub

Here is the code for the On_open event of frmMain

Code:
Private Sub Form_Open(Cancel As Integer)
LoginName = Me.OpenArgs
End Sub

Good luck
 
Hi

Here is the code for the on_click event of the Login Button

Good luck

<slaps own forehead> A classic case of not seeing the wood for the trees. Thank you very much, Rabbie. Not only does the code work now, but, much more importantly, I've seen where I was going wrong in the first place.

Thanks again.
 
<slaps own forehead> A classic case of not seeing the wood for the trees. Thank you very much, Rabbie. Not only does the code work now, but, much more importantly, I've seen where I was going wrong in the first place.

Thanks again.
Glad to hear you have got it fixed. Always happy to help people learn:)
 

Users who are viewing this thread

Back
Top Bottom