Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login Form - No Security Needed

Status
Not open for further replies.

Fireman1143

IS-IT--Management
Mar 5, 2002
51
US
I am setting up an initial login screen which will have NO security function other than make someone relaize they shouldn't be trying to get into this particular database. All I want is to ask for the Username and then the Password and if both are supplied correctly it will open the main Switchboard. The fields in the tblEmployees are [strUn] for Username and [strEmpPw] for password.

Whne I enter a correct username and password I get a message "Runtime error 2001 You cancelled the previous operations" with this line highlighted.

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


-----------------------------------------------------------

Private Sub cmdLogin_Click()

'Check to see if data is entered into the UserName combo box
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

'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 tblEmployees to see if this
'matches value chosen in combo box

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

'Close logon form and open splash screen
DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "Switchboard"

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
 
I imagine strUn is a text field, if so, you need delimiters:

If Me.txtPassword.Value = DLookup("[strEmpPw]", "tblEmployees", "[strUn]='" & Me.cboEmployee.Value & "'") Then

 
Hi Fireman1143 how are ya....

I think the problem is you have a text box for the username, try replacing the textbox for the username to a combobox box with the following properties in the combobox

RowSource - SELECT tblEmployees.lngEmpID, tblEmployees.strUN FROM tblEmployees;

Column Count - 2
Column Width - 0";2";
Bound Column - 1

Now go to your tblEmployees and add another column called lngEmpID and leave it as an Autonumber. Then replace your code:

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

With the following code:

If Me.txtPassword.Value = DLookup("strEmpPw", "tblEmployees", "[lngEmpID]=" & Me.COMBOBOX-NAME.Value) Then

lngEmpMyID = Me.COMBOBOX-NAME.Value

That should do the trick.

Nim
 
Remou and Rim180,

Thank you both for the different approaches and ideas. Especially getting back to me so fast.

This did solve the problem and is doing exactly what I needed it to do.

Fireman1143 [bigsmile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top