Results 1 to 5 of 5
  1. #1
    whojstall11 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Posts
    57

    if statment or case statment?

    if statment or case statment?



    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

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245
    If Me.qpwd.Value = DLookup("Password", "Login", "UserID = '" & Me.quserid.Value & "'") Then
    DoCmd.OpenForm "MainMenu", acNormal
    Else
    MsgBox "Īnvalid User ID or Password"
    End If

    This is what mine is. I have the Dlookup checking to see if it exists if so then it opens up my form. Dlookup isnt the best security methody. for log in etc. as It is easily hack able but it gets the job done for basic stuff.

  4. #4
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    The employeeID combo box has two columns, correct? The first (hidden) is employeeID, and the second is the user name?

    But your Select Case statement is using just cboEmployee, which is the EmployeeID. You want the User Name in the select case Statement, so change Select Case cboEmployee to Select Case cboEmployee.column(1), to compare to the second column of the combo box (column numbers are zero-based).

    In addition to that, if intLogonAttempts is a local variable in that subroutine, then that counter will never work (i.e. never be > 3) because I don't see any loop in the code.

    HTH

    John

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    This question has already been asked and answered in another forum.
    See: http://www.access-programmers.co.uk/...86#post1170986
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Adding multiple SQL Statment to code
    By rlsublime in forum Programming
    Replies: 1
    Last Post: 06-20-2012, 01:22 PM
  2. is this a valid statment
    By akrylik in forum Access
    Replies: 12
    Last Post: 05-08-2012, 08:47 PM
  3. Like statment
    By brew in forum Programming
    Replies: 2
    Last Post: 12-01-2011, 03:23 AM
  4. IF statment criteria??
    By cthai in forum Queries
    Replies: 1
    Last Post: 03-19-2011, 02:51 AM
  5. SQL statment structure
    By oss_ma in forum Programming
    Replies: 1
    Last Post: 05-13-2007, 02:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums