Results 1 to 8 of 8
  1. #1
    wes9659 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2014
    Location
    Dover, Ohio
    Posts
    88

    Password A Form

    I have added the VBA code below to my form which is Named Main. I place code in the Close event. It works like a charm when I enter the password (Access123). However when I enter a different word it gives me my message box that states “You're not authorized” like it should but then when I hit OK on message box I get Microsoft Visual Basic Runtime Error ‘2501’: the close action was cancelled when I hit End it closes form anyhow and when I hit Debug it shows code with password. Any Clues??? I am using Office Access 365 I would love it if the code would revert back and ask for code to be reentered until the actual code is entered which than would allow form to be closed. Once again thanks everyone on this forum for all the help and support I have learned so much from everyone.

    Dim PassWord As String


    PassWord = InputBox("Enter Password")
    If PassWord = "Access123" Then
    ' Open Form
    exit sub
    Else
    MsgBox ("You're not authorized")
    DoCmd.Close acForm, Me.Name
    End If

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Don't use Close event. Why close event? How does user trigger the Close event - X close button? I always disable this and manage form close with custom buttons. Actually, my 'Main' form never closes, this is the main menu for the db. My Login form does close after successful login. Instead of InputBox, use a textbox on form and code in AfterUpdate event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    wes9659 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2014
    Location
    Dover, Ohio
    Posts
    88
    My Close X is disabled ,however, a person may still right click on my form and close it that way. So what event should I have triggered if you were going to use an event code how would I write code? One which would allow for a password to be entered and if password is entered correctly it would allow you to close form However, if incorrect I want it to default back to main screen and advise them they entered incorrect password.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I also disable right click and build customized menu so those tools are not available and disable the app X Close.

    Shortcut menu can be disabled by form, see ShortcutMenu property on Other tab.

    As noted, I use textbox AfterUpdate event. You already have the If Then Else code.

    Only time I've ever used Close event is behind reports. I don't know any way to cancel the Close event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    wes9659 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2014
    Location
    Dover, Ohio
    Posts
    88
    Thanks for all the help I was able to get it to point that they are unable to close last Main form as I wanted. I want now to be able to create the button you referred to that would allow me to access the tables and information with a password associated it with a button. Anyone have ideas or recommendations on writing this VBA Code? Basically, I want to hit button it will ask me to enter password if I enter correctly it will allow me access to codes and tables. If not a message box would pop up and say Invalid Password please reenter after three tries it forces you to wait say 15 min to reenter again. Once again thanks everyone and Thank You June7 for getting me this far. I really appreciate you and everyone else sharing their knowledge and wisdom.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I've never built password encrypted database. It is a common topic in forum.

    I just hold down shift key when opening db to get development mode, which, BTW, would probably bypass the password setup. Disabling/passwording shift key bypass is possible.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    wes9659 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2014
    Location
    Dover, Ohio
    Posts
    88
    I thank you anyhow for replying hopefully someone else can jump in here and help me out on creating it

  8. #8
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    I'm not sure what you're asking for is possible.

    As June7 said, security is a reoccurring topic on the Forum and nobody here (that I know of) has been able to successfully lock down an Access Database to the point that it would really be considered secure. What it comes down to is, as long as you're using an MDB or ACCDB to store the back-end data, people are going to be able to get to your Tables. You can secure your VBA Code by distributing a "compiled" MDE/ACCDE file however.

    If you're needing actual security I'd recommend moving your data to a true DBMS back-end like SQL Server (there's a free version called SQL Server Express Edition) which has built-in authentication/security that you can use to secure your Tables from unauthorized access.

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

Similar Threads

  1. Replies: 4
    Last Post: 05-10-2014, 12:50 PM
  2. Replies: 2
    Last Post: 12-24-2012, 10:15 PM
  3. Replies: 1
    Last Post: 07-24-2012, 06:10 PM
  4. Replies: 1
    Last Post: 06-22-2012, 08:05 AM
  5. Password Form
    By hitesh_asrani_j in forum Forms
    Replies: 1
    Last Post: 09-26-2011, 06:13 PM

Tags for this Thread

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