i have created a login window by using a form. And using Dlookups.
The username works fine however when i enter the password i get a type mismatch error. Here is my code so far.
Private Sub open_form_Click()
Dim Staff As String
Dim admin As String
Dim Group As Variant
Dim getpass As Variant
Staff = "Staff"
admin = "admin"
Group = DLookup("[Group]", "usernames", "[Username] = " & "'" & Me.Username & "'")
getpass = DLookup("[password]", "usernames", "[Username] = " & "'" & Me.Username & "'")
If Me.password Is Not getpass Then
MsgBox "Your password is incorrect. Access Denied"
End If
If Group = Staff Then
Dim userform As String
Dim stLinkCriteria1 As String
userform = "User Form"
DoCmd.openform userform, , , stLinkCriteria1
ElseIf Group = admin Then
Dim openform As String
Dim stLinkCriteria2 As String
openform = "Admin Form"
DoCmd.openform openform, , , stLinkCriteria2
End If
End Sub
Also after the access denied message has been displayed i would also like to set the password field on the form to blank and then to stop before going onto to load the seperate forms. I have only been writing code for a few weeks... am i going about it in the right way?
If anyone could help i would be most grateful.
Many Thanks
The username works fine however when i enter the password i get a type mismatch error. Here is my code so far.
Private Sub open_form_Click()
Dim Staff As String
Dim admin As String
Dim Group As Variant
Dim getpass As Variant
Staff = "Staff"
admin = "admin"
Group = DLookup("[Group]", "usernames", "[Username] = " & "'" & Me.Username & "'")
getpass = DLookup("[password]", "usernames", "[Username] = " & "'" & Me.Username & "'")
If Me.password Is Not getpass Then
MsgBox "Your password is incorrect. Access Denied"
End If
If Group = Staff Then
Dim userform As String
Dim stLinkCriteria1 As String
userform = "User Form"
DoCmd.openform userform, , , stLinkCriteria1
ElseIf Group = admin Then
Dim openform As String
Dim stLinkCriteria2 As String
openform = "Admin Form"
DoCmd.openform openform, , , stLinkCriteria2
End If
End Sub
Also after the access denied message has been displayed i would also like to set the password field on the form to blank and then to stop before going onto to load the seperate forms. I have only been writing code for a few weeks... am i going about it in the right way?
If anyone could help i would be most grateful.
Many Thanks