Results 1 to 2 of 2

Thread: password code

  1. #1
    Join Date
    Jul 2003
    Posts
    42

    Unanswered: password code

    I am trying to get a password code to work based on a button:

    Is there a way to open different forms based on the password entered.
    Meaning....if the buyer enters the buyer password "buyersave" they get the buyer switchboard, but if the production group enters the production password "prodreview" they get the production switchboard. I also need it to close after its done.

    The below code was done for one password but isnt working. How do I fix it and change it to work for the above scenario. Thank you.

    Private Sub EnterPass_Click()

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "01-StartBuyer"

    If Me![Password] = "buyersave" Then
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    stDocName = "SB01-BuyerSB"
    DoCmd.Close acForm, stDocName
    stDocName = "01-StartBuyer"
    DoCmd.Close acForm, stDocName
    Else
    End If

    End Sub

    Note: "01-StartBuyer" is the form that is open that contains the unbound password entry box "Password" and the button "EnterPass" I am trying to get it to open the "SB01-BuyerSB" form after the correct password is entered. Also, if the password is wrong how do you give them a message telling them it is incorrect?

  2. #2
    Join Date
    Nov 2002
    Posts
    49
    Try this code

    Private Sub EnterPass_Click()

    Dim stDocName As String
    Dim stLinkCriteria As String

    Select Case password
    Case "buyersave"
    stDocName = "01-StartBuyer"
    DoCmd.OpenForm "SB01-BuyerSB", , , stLinkCriteria
    DoCmd.Close acForm, stDocName
    Case Else
    MsgBox "You have entered an invalid password"
    password = Null
    End Select


    End Sub


    Your code was written to open "01-StartBuyer", then close "SB01-BuyerSB", then close "01-StartBuyer". A little confusing, but what it did, was close everything.
    The select case will allow you to add additional forms as needed.

    I usually prefer a table set up with fields txtPassword, and txtForm. This wolud allow you to change the passwords through the application versus the code, but if security isn't an issue, your way is just as good.

    Hope this helps.

Posting Permissions

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