if statment or case statment?

whojstall11

Registered User.
Local time
Today, 10:59
Joined
Sep 7, 2011
Messages
94
I want to write an if or case statement that opens my form depending on the criteria.
i have tried both neither work.
Code:
 If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
 
        lngMyEmpID = Me.cboEmployee.Value
        Select Case cboEmployee
   Case "Admin"
DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "Main Page Navigation Form"
Case "Other"
 DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "Main Page Navigation Form User"
End Select
        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 your system administrator.", vbCritical, "Restricted Access!"
        Application.Quit
    End If
 
End Sub
 
I modified your code a bit (ask questions if not sure why I did something):
Code:
    Static intLogonAttempts As Integer

    If Me.txtPassword.value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.value) Then
        lngMyEmpID = Me.cboEmployee.value
        With DoCmd
            Select Case cboEmployee
            Case "Admin"
                .OpenForm "Main Page Navigation Form"
            Case "Other"
                DoCmd.OpenForm "Main Page Navigation Form User"
            Case "Admin", "Other"
                .Close acForm, Me.Name, acSaveNo
            End Select
        End With
    Else
        '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 your system administrator.", vbCritical, "Restricted Access!"
            Application.Quit
        Else
            MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
            Me.txtPassword.SetFocus
        End If
    End If
 
End Sub
 
My guess is that "cboEmployee" is a combo box and that its first column width is set to 0cm so the second column is the one see. First column holds a number. Second column holds text ("Admin" etc).

If this is correct then I think that
Code:
Select Case cboEmployee
needs to be:
Code:
Select Case cboEmployee.Column(1)
 
Bob's assessment is most likely right as I forgot to look at that.
 
OOOOK i feel stupid thank you
I don't think you should feel bad.
IMHO:
Nobody knows everything.
Nobody remembers everything they have been told.
And nobody goes through life without making some mistakes, even if they do know.

Just as well really, otherwise there would be no use for forums like this.:)
 

Users who are viewing this thread

Back
Top Bottom