Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Login VBA code

WilkoWilko Member Posts: 8
[b][red]This message was edited by Wilko at 2006-2-17 6:30:8[/red][/b][hr]
Hi there,

I have adapted a piece of code to allow users to login into the database. I have two types of users, that of student and that of admin. If the admin logs in I want them to be taken to a different form than ordinary users.

Here is the code i have so far



Code:
Private Sub Login_Click()

'Check to see if data is entered into the UserName combo box

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

'Check to see if data is entered into the password box

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

'Check value of password in tblUsers to see if this
'matches value chosen in combo box

If Me.txtPassword.Value = DLookup("Password", "Users", "[UserID]=" & Me.cboUser.Value) Then

UserID = Me.cboUser.Value

If Me.cboUser = AdminID Then
DoCmd.OpenForm "AdminForm"
Else
DoCmd.OpenForm "Studentform"
End If - My attempt at trying to get them to go to different forms!

'Close logon form and open splash screen

'DoCmd.Close acForm, "frmLogn", acSaveNo
'DoCmd.OpenForm "Questions" Just a test to see if it would open a form




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

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact admin.", vbCritical, "Restricted Access!"
Application.Quit
End If


End Sub

the problem is that I can get the code to go to one form, but it will always be the same, no matter who logs in admin or student. I want them to go to different forms.


Code:
If Me.txtPassword.Value = DLookup("Password", "Users", "[UserID]=" & Me.cboUser.Value) Then

UserID = Me.cboUser.Value

If Me.cboUser = AdminID Then
DoCmd.OpenForm "AdminForm"
Else
DoCmd.OpenForm "Studentform"
End If - My attempt at trying to get them to go to different forms!

The above code doesnt work - I think the logic is correct but im not sure what syntax to use.. Basically if Admin logs in, load admin form, else load student form. Hope that explains better!


Any help would be much appreciated

Ross

Sign In or Register to comment.