Results 1 to 2 of 2
  1. #1
    Join Date
    May 2014
    Posts
    14

    Unanswered: Password A Form on Closing

    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
    Join Date
    Oct 2003
    Location
    London
    Posts
    341
    By any chance does your DoCmd.Close action have the right form name? Me.Name / Me.Main?
    Last edited by Missinglinq; 02-16-15 at 10:47.

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
  •