Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2002
    Location
    New Zealand
    Posts
    19

    Unanswered: vb Code Check for Password - Help

    Hi,
    I am not an expert just a grunt, but have pasted together the following code for a password entry. There is a Table called Password and a Feild called Password for the DLookup to work, and the Password for testing is 1234.
    Could some one check the following code .
    I can't get case 2 or case 3 to work.
    Do I need something after the else in Case 1?
    It's for Management OK for sell price lower than permitted.
    If The input and backdoor password are OK then the current form should print out but they don't. The code loops. The loop was to let Management have some attempts if they forgot there password.
    The input strPW2 returns "incorrect Password which when I look at it, so it should. What do I need to get this to run?

    If (Me![Sell Price] <= Me![Cost Price] * 1.15) Then
    ' Display message box to inform the user that Management OK is needed for this price.
    strTitle = "Management OK is needed for this sell price"
    strMsg = "The Sell Price is incorrect. The Value is Less Than 15%!!!." & vbNewLine & "Press Yes to correct Sell Price." & vbNewLine & "Or No to Open Controls for Management to Accept Sell Price."
    If MsgBox(strMsg, vbQuestion + vbYesNo) = vbYes Then
    [Sell Price].SetFocus
    Exit Sub

    Else

    Dim Password As String, strinput As String, strPW2 As String, strMsg1 As String, strTitle1 As String
    strMsg1 = "Incorrect Password" & vbNewLine & "Please Try Again"
    strTitle1 = "Invalid Password"
    Password = DLookup("Password", "Password")
    strPW2 = "wapfu"
    Do Until intCnt = 6 Or strinput = Password Or strinput = strPW2
    strinput = InputBox("Enter Password")
    'Check if Input "Is Not Equal" to Password
    Select Case strinput <> Password

    Case 1
    If MsgBox(strMsg1, vbCritical + vbYesNo, strTitle1) = vbYes Then
    intCnt = intCnt + 1
    Else
    Exit Sub
    End If

    Case 2
    strinput = Password
    MsgBox "Entry Is Successfull, Thankyou."
    DoCmd.PrintOut acSelection
    DoCmd.SAVE
    DoCmd.close
    Exit Sub

    Case 3
    strinput = strPW2
    MsgBox "Entry Is Successfull, Thankyou."
    DoCmd.PrintOut acSelection
    DoCmd.SAVE
    DoCmd.close
    Exit Sub
    End Select
    Loop

    End If

    Thanking in advance
    Kind Regards
    Bill

  2. #2
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    the expression strinput <> Password can only be true(-1) or false(anything other). So you can just use an if/else construct:
    Code:
    if strinput = Password then
        If MsgBox(strMsg1, vbCritical + vbYesNo, strTitle1) = vbYes Then 
            intCnt = intCnt + 1 
        Else 
            Exit Sub 
        end if
    else
        strinput = Password 
        MsgBox "Entry Is Successfull, Thankyou." 
        DoCmd.PrintOut acSelection 
        DoCmd.SAVE 
        DoCmd.close 
        Exit Sub 
    end if

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •