I need to create a very simple login screen for the program I'm working on. The users table has only 3 fields, user_id, name and password. Nothing futher is needed.
The login screen has two unbound boxes Name and Password. When the user enters their name (which is in the format of joesmith) and the password, they push the continue button. Which will run the code to first verify that the usernames name is in the table and if its there, then checks the validity of the password. If both are correct, it opens the form.
I'm using IF then Else statements,
If users name is correct Then
If password is correct Then
Open form
Else
Display message - Password Incorrect
End IF
Else
Display message - Name incorrect
End IF
I have the code for the message boxes and to open the form and they do work. I'm just having trouble figuring out how to take the entry from the unbound text entries and checking them against the table.
I need examples of the actual code. I'm not a programmer, but lately I have been.
Cheryl
Have a look at a sample Login database at http://forums.databasejournal.com/sh...ad.php?t=45488 go to message number 10. This may help you. This database checks the user id and password then opens a form depending on the user's access level. I know it slightly more than you require.
Contact me if you require more information
I have attached a sample login database that will suit your requirements. Open the form frm_main, this is the login screen.
In the attached database have a look at the module mod_display_menu shown below
After the User clicks on the Enter button on the main menu this module
1. Checks for a valid user id
2. If a valid user id then it checks the password on the main form is the same as the password stored in tbl_users.
3. Displays an error message if not a valid user id or password
4. If a valid user then it opens the form frmntwnar and closes the login screen.
Contact me if you require more information etc.
' Name: mod_display_menu
' Function : display the form after checking the login id and password
' Date: 29/12/2007
Option Compare Database
Option Explicit
Sub display_menu()
On Error GoTo err_display_menu
' at this stage the userId and access level has been checked
Dim valid_user As Integer
Dim check_user As Integer
Dim check_password As String
Dim strmsg As String
' set valid user flag to 2. 2 is for a valid user
valid_user = 2
' **********************************************
' validate user_id
' if the user from the login screen in in tbl_users then set the valid_user flag to 2
' if not a valid user set the flag to 0
' **********************************************
check_user = DCount("[user_id]", "tbl_users", "user_id=forms!frm_main!user_id")
If check_user = 1 Then
valid_user = 2
Else
valid_user = 0
End If
' **********************************************
' validate password
' if the valid user flag is 2 then
' obtain the password in tbl_users
' compare the password from tbl_users with the login password
' if a valid password then set valid user flag to 2
' if not a valid password set valid user flag to 1
' **********************************************
If valid_user = 2 Then
check_password = DLookup("[password]", "tbl_users", "user_id=forms!frm_main!user_id")
If UCase(check_password) = UCase(Forms!frm_main!password) Then
valid_user = 2
Else
valid_user = 1
End If
End If
'depending on the value of the valid user flag
' display a suitable message if an invalid user id or password
' for a valid user open the form frmntwnar
Select Case valid_user
Case 0, 1
strmsg = " Access Denied" & _
vbCrLf & " Contact your Administrator if the problem persists. "
MsgBox strmsg, vbInformation, "INVALID USER ID or PASSWORD"
Case 2
' valid user id and password
' open the form frmntwnar
DoCmd.OpenForm "frmntwnar"