If statement not doing what I expect

ggreg

Registered User.
Local time
Today, 19:27
Joined
Aug 12, 2002
Messages
66
See below in comments what my problem is:

Private Sub Command4_Click()
Dim strSQL As String
If IsNull(Me.txtLogin) Or Me.txtLogin = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.txtLogin.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 strSQL = DLookup("[strEmpName]", "tblEmployees", "[strEmpName]='" & Forms!frmlogin!txtLogin & "'") Then

'The above is not doing what I think it should be doing
'I know I have a lot more coding but just trying to test this one part
'ok at this point if a name that is in the tblEmployees is there
'instead of it opening frmMain it jumps to the else and tells me
'Password Invalid why is it jumping to the else and what do I have
'to do at this point to get it to open frmMain if a name is in the table?
'Thanks in advance!


DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "frmMain"
:confused: Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
 
You're not filling the strSQL string before you try to compare it to your DLookup. strSQL is empty.
 
thanks!!!

I ended up using
If strSQL = Me.txtLogin Then
 
Last edited:
You could just change this line:
If strSQL = DLookup("[strEmpName]", "tblEmployees", "[strEmpName]='" & Forms!frmlogin!txtLogin & "'") Then
to this:
If me.txtLogin = DLookup("[strEmpName]", "tblEmployees", "[strEmpName]='" & Forms!frmlogin!txtLogin & "'") Then

I'm not saying this is optimum, I just think that with the code you presented, this should make it work.
 
wow thanks for posting so quick I just may look at your option too~ :)
 
how do I get bad response to the names in the table meaning
if they put a wrong name in there how do I trap for that error?
because now it not doing the else it is throwing an error

wow I see my way does not work but your way does...
now tho this part of my code is not working:

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

its not counting my attempts
 
Last edited:
Go to the declarations section at the top of the code page and put this:
Private intLogonAttempts as Byte
 

Users who are viewing this thread

Back
Top Bottom