How to create a password for access forms

Posted on 2009-04-20
Last Modified: 2012-05-06
I have created the password for the form, as directed by the experts here, but i have to create another password for the form, that has "add material number". I have attached the database for u, if you can open the database, the main menu appears and pops up a password dialog box, I need exactly same asking for a pasword the user clicks the "add material menu". In my database, a password box should appear as it appears for the "main menu". can you please give a suggestion. Thanks

Question by:jpeterjeyaraj
    LVL 13

    Accepted Solution

    each form requests the password for its form name.

    so go into tblpassword and add an entry for :
    [objectname]                           [keycode]
    ADD NEW MATERIAL MENU       whateveryouwantthepasswordtobe
    LVL 13

    Assisted Solution

    if you add this code to any other forms you would need to add those to tblpassword as well.

    Author Comment

    can you please detail me about this still its give me a error message. I added one column as add material menu in table password and keycode as 1234. should I also create a form password fo this add material menu? Please advise me, thanks
    LVL 13

    Assisted Solution

    ok. it seems the password code was not working for me so i changed it.

    anyway first open main menu form in design view and rigtclick the "ADD NEW MATERIAL NUMBER" button and choose properties.
    under the events tab doubleclick in the emy text behind onclick (so it says [event procedure]) and then click the button behind it.

    insert the code to open the form:

    Private Sub ADD_NEW_MATERIAL_NUMBER_Click()
     End Sub

    then open the "add new material menu" form and in the properties window under events doubleclick behind the "on open" event. i changed the on open code to:

    Private Sub Form_Open(Cancel As Integer)
       Dim Hold As Variant
       Dim tmpKey As Long
       Dim I As Integer
       Dim rs As DAO.Recordset
       Dim db As DAO.Database

       On Error GoTo Error_Handler
       ' Prompt the user for the Password.
       DoCmd.OpenForm "frmPassword", acNormal, , , , acDialog
                Hold = MyPassword
    ' Open the table that contains the password.
       Set db = CurrentDb
       Set rs = db.OpenRecordset("tblPassword", dbOpenTable)
       rs.Index = "PrimaryKey"
       rs.Seek "=", Me.Name
       If rs.NoMatch Then
          MsgBox "Sorry cannot find password information. Try Again"
          Cancel = -1
          ' Test to see if the key generated matches the key in
          ' the table; if there is not a match, stop the form
          ' from opening.
          If Not (rs![keycode] = CStr(Hold)) Then
     ' above line was changed from :     If Not (rs![keycode] = keycode(CStr(Hold))) Then
             MsgBox "Sorry you entered the wrong password." & _
                "Try again.", vbOKOnly, "Incorrect Password"
             Cancel = -1
          End If
       End If
       Exit Sub

       MsgBox Err.DESCRIPTION, vbOKOnly, "Error #" & Err.Number
       Exit Sub
    End Sub

    LVL 13

    Assisted Solution

    visual aid

    Author Comment

    How can i give a password of my choice, any advice please. and also if you open the above database, if you open for the first time, it asks for passowrd and then if you open the main menu it asks for password or If I close the password form I can able to access even though if I dont enter the password.Any suggestion how to rectify this problem. Thanks,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now