Results 1 to 5 of 5
  1. #1
    michaelwh1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    9

    Form closing unexpectedly

    I have been using Access for a while now and while not an expert feel failrly comfortable with it. I have a form with a command button that launches another form but has to have the correct password for the load event to continue. If the password is correct then all works well. If not then the code says to close the form and return to the original screen. However, when the password is not correct it not only aborts opening the form but closes the original form as well. I have tried to see what is causing this but I simply cannot find out why. Any help[ is appreciated. Below is the script.

    Private Sub Form_Load()
    Dim PassWord As String
    PassWord = InputBox("Enter Password")
    If PassWord = "pass" Then
    ' Open Form
    DoCmd.OpenForm "frmDataManage"
    Else
    MsgBox ("You're not authorized")
    DoCmd.Close acForm, "frmDataManage"
    DoCmd.OpenForm "frmMainScreen"


    End If

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    Why is this in a form Load event? Why not the button Click event? Which form is this code behind?
    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
    michaelwh1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    9
    Thanks. I had read that the load event was the correct place to have the script. I moved ot to thye click event and it solved the problem.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    Not Load, could use Open event of frmDataManage which has an argument for Cancel:

    Private Sub Form_Open(Cancel As Integer)
    If InputBox("Enter Password") <> "pass" Then
    Cancel = True
    MsgBox ("You're not authorized")
    DoCmd.OpenForm "frmMainScreen"
    End If
    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
    michaelwh1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    9
    Thanks. That also works.

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

Similar Threads

  1. Records unexpectedly locked
    By always404 in forum Forms
    Replies: 9
    Last Post: 01-31-2013, 05:05 PM
  2. Replies: 1
    Last Post: 04-14-2012, 01:13 PM
  3. Replies: 3
    Last Post: 12-19-2011, 11:39 AM
  4. Closing a form through VBA
    By ghostmachine in forum Forms
    Replies: 4
    Last Post: 12-13-2010, 01:57 PM
  5. Closing and saving a form
    By Lxmanager in forum Forms
    Replies: 14
    Last Post: 11-21-2010, 02:04 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