Login to different things

bdb25

Registered User.
Local time
Today, 06:51
Joined
Feb 22, 2007
Messages
19
Hey i'm using the login form from databasedev, and in the tblusers theres a place for either Admin or User, i was wondering what script would have to be included in the login to get Admin's directed to the SwitchboardAdmin and the Users to be directed to SwitchboardUsers.

I've attached the file i'm using, if anyone can help it would be greatly appreciated as i dont know what i'm doing when it comes to scripting :(

i figre it would be something along the lines of if strlevel = Admin then go to such n such if strLevel = User then go to such n such.

this said, i have no idea in how to put that into a script that works :P

thanks
 

Attachments

use a dlookup to get the user level (strlevel)
then

Code:
Dim Struserlevel as string
struserlevel = DLookup("strlevel", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value)
        If (strUserlevel = "Admin") Then
        DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "SwitchboardAdmin"
        Else
        DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "SwitchboardUsers"
        end if
Something along those lines
 
i've had a mess about and tried to add it into the code so now it reads


Code:
'Close logon form and open splash screen
        
Dim Struserlevel As String
Struserlevel = DLookup("strlevel", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value)
        If (Struserlevel = "Admin") Then
        DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "SwitchboardAdmin"
        Else
        DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "SwitchboardUsers"
        Else
        MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If

however when i try and run this code it says Compile Error Else without If

sorry that i need it step by step

i've attached the file again with the script in that i've added

thanks again
 

Attachments

You currently have two Else statements and for an If...Then...Else you can only have one unless you use ElseIf statements after the inital Else.
 
So therefore my code should look something along the lines of.....

Code:
Private Sub cmdLogin_Click()

    If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
            MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
            Me.cboEmployee.SetFocus
        Exit Sub
    End If

    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
            MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
            Me.txtPassword.SetFocus
        Exit Sub
    End If

    If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then

        lngMyEmpID = Me.cboEmployee.Value
       
        Dim Struserlevel As String
        Struserlevel = DLookup("strlevel", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value)
        If (Struserlevel = "Admin") Then
        DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "SwitchboardAdmin"
        
        Else
        DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "SwitchboardUsers"

        ElseIf
        MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If
    
End Sub

only thing is when i type in ElseIf it turns red and a prompt is displayed saying Compile Error: Expected Expression

am i missing something really simple? (probably knowing me)
 
Actually, I led you slightly astray. Sorry, it's Monday and my brain isn't working too well.

You should try changing it to this:
Code:
Private Sub cmdLogin_Click()

    If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
            MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
            Me.cboEmployee.SetFocus
        Exit Sub
    End If

    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
            MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
            Me.txtPassword.SetFocus
        Exit Sub
    End If

    If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then

        lngMyEmpID = Me.cboEmployee.Value
       
    End If

        Dim Struserlevel As String
        Struserlevel = DLookup("strlevel", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value)
	Select Case Struserlevel
		Case "Admin"
		        DoCmd.Close acForm, "frmLogon", acSaveNo
		        DoCmd.OpenForm "SwitchboardAdmin"
        
        	Case "User"
		        DoCmd.Close acForm, "frmLogon", acSaveNo
		        DoCmd.OpenForm "SwitchboardUsers"

		Case Else

        		MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
        		Me.txtPassword.SetFocus
    	End Select
    
End Sub
 
thanks so much for all your help, works like a charm now :D woo

edit: ok i spoke too soon, it works, however, even if the password is wrong, it still logs you in *-) is there anyway of getting around this, i've had a play at moving different parts around, and i can get it to say "invalid password" however it still goes on to load the switchboard.:confused:
 
Last edited:
move your case statement inside the if statement that u have that checks the password

Code:
Private Sub cmdLogin_Click()
    If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
            MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
            Me.cboEmployee.SetFocus
        Exit Sub
    End If
    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
            MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
            Me.txtPassword.SetFocus
        Exit Sub
    End If
    If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
        lngMyEmpID = Me.cboEmployee.Value
        Dim Struserlevel As String
        Struserlevel = DLookup("strlevel", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value)
	Select Case Struserlevel
		Case "Admin"
		        DoCmd.Close acForm, "frmLogon", acSaveNo
		        DoCmd.OpenForm "SwitchboardAdmin"
        
        	Case "User"
		        DoCmd.Close acForm, "frmLogon", acSaveNo
		        DoCmd.OpenForm "SwitchboardUsers"

		Case Else

        		MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
        		Me.txtPassword.SetFocus
    	End Select
Else
Msgbox "Error: Username and password do not match"
    end if
End Sub
 

Users who are viewing this thread

Back
Top Bottom