Results 1 to 12 of 12
  1. #1
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52

    Password protected form or report


    I found a sample mdb file on the internet that I want apply its functions on my database. Its works perfectly, however..when I type the password in the inputbox..the password was visible. The inputbox was created using codes not the usual textbox in design view. Is their a way to change its input mask property to PASSWORD?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You have picked a good example to learn a little VBA. The InputBox() function does not have a "Password" feature but a TextBox control on a form *does*. Just add a TextBox to your form with the InputMask set to Password and then "borrow" some of the code in the module to verify the value.

  3. #3
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    Noted.
    While waiting a reply from access experts, I searched again the web and found another sample (has to type to type the code) from microsoft, http://support.microsoft.com/kb/209871. The input mask for the textbox is "PASSWORD". I tried it, however..I get a Compile error. I'm lost, need help. Please see attached mdb.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You need to add the DAO library to your references: http://www.btabdevelopment.com/ts/missref

  5. #5
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    I checked Microsoft DAO 3.6 Object Library and the compilation error disappeared. But, I get the password error message " Sorry you entered the wrong password. Try Again". I entered a new password in tblPassword for the ObjectName "Orders" but I still get the error message everytime I open Orders. Help..

  6. #6
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    me.name would be the name of the form as the password (ie. form1, form2, form3) wouldn't it?

  7. #7
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    I'm unable to get it working, I replaced me.Name to Me.Orders but I got Compile error. I changed it to Me!Orders but I got this error Microsoft Access can't find 'Orders' referred to in your expression.

    Code:
    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
       DoCmd.OpenForm "frmPassword", acNormal, , , , acDialog
                Hold = MyPassword
    
       Set db = CurrentDb
       Set rs = db.OpenRecordset("tblPassword", dbOpenTable)
       rs.Index = "PrimaryKey"
       rs.Seek "=", Me!Orders
       If rs.NoMatch Then
          MsgBox "Sorry cannot find password information. Try Again"
          Cancel = -1
       Else
             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
       rs.Close
       db.Close
       Exit Sub
    
    Error_Handler:
       MsgBox Err.Description, vbOKOnly, "Error #" & Err.Number
       Exit Sub
    End Sub

  8. #8
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    anybody there? I really don't have any idea regarding VB, help.

  9. #9
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Try looking at this non-permission's based mdb example - it keeps track of users (automatically recognizing who's logging in) and what level of security they have to make a button/text box/etc.. visible/locked/invisible:

    https://www.accessforums.net/code-re...mple-7538.html

  10. #10
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    I'll look into it.

    I really appreciate if you could help me find the fix (why password doesn't work) on the Password Required.mdb. Please help.

  11. #11
    Reaper is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2011
    Posts
    57
    This is a little late, but here it goes.

    I had the same problem with this exact code. The problem is with the password check line of the code. If Not (rs![KeyCode] = KeyCode(CStr(Hold))) Then

    You'll notice that the "keycode" function "KeyCode(CStr(Hold))" is used to compare to the unmodified entry from your password table "rs![KeyCode]". This will ALWAYS result in no match.

    I see no reason for the password encryption, so I eliminated the function and compared them directly. Replace "KeyCode(CStr(Hold))" with "MyPassword" and it will work fine.

    The code will look like:

    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
    DoCmd.OpenForm "frmPassword", acNormal, , , , acDialog
    Hold = MyPassword

    Set db = CurrentDb
    Set rs = db.OpenRecordset("tblPassword", dbOpenTable)
    rs.Index = "PrimaryKey"
    rs.Seek "=", Me!Orders
    If rs.NoMatch Then
    MsgBox "Sorry cannot find password information. Try Again"
    Cancel = -1
    Else
    If Not (rs![KeyCode] = MyPassword Then
    MsgBox "Sorry you entered the wrong password." & _
    "Try again.", vbOKOnly, "Incorrect Password"
    Cancel = -1
    End If
    End If
    rs.Close
    db.Close
    Exit Sub

    Error_Handler:
    MsgBox Err.Description, vbOKOnly, "Error #" & Err.Number
    Exit Sub
    End Sub

  12. #12
    tomt@coned.com is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    1
    I know that this is later than usual for the above question about password. But I am having the same problem. I have modified the code so that "rs.Seek "=", Me!Orders" however, it keeps coming back Field Not Found. This is a database that is going to be used by multiple users with a Switchboard menu. However, I have to set password on one of the forms so that it cannot be access except for a few individuals. The above seems like such a simple code and should run but I just can't figure it out. Please help

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

Similar Threads

  1. Open a password protected MDB/MDW
    By abcc14 in forum Security
    Replies: 8
    Last Post: 11-02-2011, 07:41 AM
  2. Replies: 4
    Last Post: 09-14-2011, 12:33 AM
  3. Virtual Password-Protected Connection
    By marianne in forum Sample Databases
    Replies: 6
    Last Post: 02-18-2011, 10:41 AM
  4. Replies: 1
    Last Post: 10-20-2010, 09:26 PM
  5. Replies: 0
    Last Post: 10-22-2007, 02:15 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