Need Help urgent Please..

ismith

Registered User.
Local time
Today, 05:22
Joined
Dec 14, 2011
Messages
30
Hello,

Im making an order system with a multi log in user page. The owner and staff can log on. Atm ive got it working so that if a staff logs on it goes to their main menu and if the owner logs on it goes to the owner menu.

To do this ive used the following code:

Code:
Public Sub btnLogin_Click()

    'This defines the attributes that are going to be used for the login page.
    'dbs is set as the Database, ownerPwd as a Record and matchFound as Boolean
    'This is so that I can assign values to them accordingly.
    Dim dbs As Database
    Dim ownerPwd As Recordset
    Dim staffPwd As Recordset
    Dim matchFound As Boolean
    Dim staffMatchFound As Boolean
    
    'dbs is set to the Database that I have created in Access.
    'I created a query in access so ive used that query to be set as ownerPwd.
    Set dbs = CurrentDb
    Set ownerPwd = dbs.OpenRecordset("qryUserPass")
    Set staffPwd = dbs.OpenRecordset("tblStaffLogin")
    
    'Set this as False so I can change it to True when the If statement is met.
    matchFound = False
    staffMatchFound = False
    'This checks in the Table to see if there is any data. It then moves to
    'the first row of data in the table.
    If ownerPwd.RecordCount > 0 Then
    ownerPwd.MoveFirst
    
    If staffPwd.RecordCount > 0 Then
    staffPwd.MoveFirst
    
    'This loop carries on while ownerPwd is False.
    'It looks into the query for ownerPwd and checks to see if the Username and Password
    'field and the same as what has been entered in the text boxes.
    'If it is the same it sets matchFound to True and breaks out of the loop.
    'If it is not then it moves onto the next row and does the loop again.
    Do While ownerPwd.EOF = False
    If ownerPwd![UserName] = Form_frmLogin.txtUsername.Value And ownerPwd![Password] = Form_frmLogin.txtPassword.Value Then
        matchFound = True
        Exit Do
    End If
        ownerPwd.MoveNext
    Loop
 End If
 
     Do While staffPwd.EOF = False
    If staffPwd![UserName] = Form_frmLogin.txtUsername.Value And staffPwd![Password] = Form_frmLogin.txtPassword.Value Then
        staffMatchFound = True
        Exit Do
    End If
        staffPwd.MoveNext
    Loop
 End If
 
 'This tells the program to close the Login form and open the main menu IF
 'the Username and Password is correct.
 If matchFound = True Then
    DoCmd.Close acForm, "frmLogin"
    DoCmd.OpenForm "frmMainMenu"

'If the Username and Password is incorrect then it shows the following message in a dialogue box.
 ElseIf staffMatchFound = True Then
    DoCmd.Close acForm, "frmLogin"
    DoCmd.OpenForm "frmStaffMainMenu"
    
    Else
    
    MsgBox "Incorrect Username or Password, Please try again", vbCritical, "Error"
End If

'This closes the database that I opened at the start
ownerPwd.Close
staffPwd.Close

End Sub

Now thats working.

What im doing now is that ive got a few buttons on both Menus which link to the same page, Such as:

The owner and staff can place Order, Add Product, Add customer etc.

So im going to link the menu to the same page for both logins.
----------------------------------------------------------------------
The part im stuck on atm is

When i click on the product page and then close it. It always goes back to the owners main menu even though im logged on with the staff logon.

Is there a way i can put coding on the close button on each of the forms such as Order, Product and Customer to say:

When btnClose.onclick
If frmStaffMainMenu is open then
Docmd.close "frmProduct"
Docmd.Open acForm, "frmStaffMainMenu"

Else

Docmd.close "frmProduct"
Docmd.Open acForm, "frmMainMenu"

End if

Is there anyway i can do something like this so the system knows if the staff is logged on and the close button is pressed then it should take them to the staff main menu and if the onwer is logged on as the close button is pressed then it should open the owner log on.


Really appreciate the help.

Thanks.
 
Firstly, to answer your question, usually people just leave the login form open but hidden so that user priveledges can be known in the front end. That's the easy way.

Secondly, why in the world are you doing it like this? You should search the web for login examples. It seems you are pulling passwords in a very round-a-bout way.

edit-Also, the title of your threads should describe the issue you are having.
 

Users who are viewing this thread

Back
Top Bottom