Results 1 to 8 of 8
  1. #1
    dascoli is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    16

    Run-Time Error 2450

    I'm sure this has been hashed out many times, but I cannot figure out a solution that works for my DB. I am seriously new to coding VBA and have implemented the security features found in this tutorial: http://www.accesssecurityblog.com/po...ccess-VBA.aspx.



    I have disabled the Navigation Pane, Ribbon, etc. so that way the database is only able to be edited by holding Shift and opening the DB.

    The problem only exists when I open the DB like a user would.

    The problem comes when I try to exit the DB with the frmMainMenu still open. If I close this form (via a command button) prior to closing the DB I don't get the 2450 error. If I close the DB while the frmMainMenu is still open I get the 2450 error.

    The error states that:
    Code:
    "[The DB] cannot find the referenced form 'frmLogin'.
    The above guide had me hide frmLogin, but not close it, so as to maintain the user-level security to be referenced by VBA code in other forms.
    This is the code that was used in frmLogin to manage the security:
    Code:
    Private Sub txtPassword_AfterUpdate()
    
    'Check that a user is selected
    If IsNull(Me.cboUser) Then
        'If no user is selected, display message box
        MsgBox "Please select a user before entering a password.", vbCritical
        'Move cursor into USER field
        Me.cboUser.SetFocus
    Else
        'Check for correct password
        If Me.txtPassword = Me.cboUser.Column(2) Then
            'Check if password needs to be reset
            If Me.cboUser.Column(3) = True Then
                DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
            End If
            'Open MAIN MENU if PASSWORD is correct
            DoCmd.OpenForm "frmMainMenu"
            'Hide LOGIN form
            Me.Visible = False
        Else
            'Upon incorrect password, display message box
            MsgBox "Incorrect password. Please try again.", vbCritical
            'Empty PASSWORD field for re-entry
            Me.txtPassword = Null
            'Move cursor to the PASSWORD field
            Me.txtPassword.SetFocus
        End If
    End If
    End Sub
    The code in red is where I hide the form.

    I don't know what the problem is since the form is still technically open (just hidden). I have tried a couple of different approaches to solving this, but none have been successful.

    I would love a solution where I don't have to remove the application close button (big 'X'). That is a lot more coding than I would like to do.

    Thanks for any help you guys are able to provide!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Is there code in the load event of the main menu form that refers to the login form?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    dascoli is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    16
    There is code in the load even of the main menu that refers to the login form.

    Here it is:
    Code:
    Private Sub Form_Load()'Check user access level from LOGIN form
    If (DLookup("[AccessLevelID]", "tblUser", "[UserID] = " & Forms!frmLogin!cboUser) = 2) Or (DLookup("[AccessLevelID]", "tblUser", "[UserID] = " & Forms!frmLogin!cboUser) = 4) Then
        'Hide developer menu button
        Me.cmdDev.Visible = False
    End If
    'Check user access level from LOGIN form
    If (DLookup("[AccessLevelID]", "tblUser", "[UserID] = " & Forms!frmLogin!cboUser) = 3) Or (DLookup("[AccessLevelID]", "tblUser", "[UserID] = " & Forms!frmLogin!cboUser) = 5) Then
        'Hide developer menu button
        Me.cmdDev.Visible = False
        'Hide employee menu button
        Me.cmdEmp.Visible = False
    End If
    End Sub

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You appear to have run into the same quirk that I and one other MVP have run into; the load event firing on exit. I couldn't beat it so I trapped for that error number so it would simply quit silently. If you're unfamiliar with error trapping:

    http://www.baldyweb.com/ErrorTrap.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    dascoli is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    16
    Thank you so much for your help pbaldy! I'll try that out!

    EDIT: That worked perfectly! I added the error trap to the load event and it works flawlessly! It closes now with no error. Thank you so much for your help with this! I was pulling my hair out last week!
    Last edited by dascoli; 05-28-2013 at 09:58 AM. Reason: Added code result.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help! That cost me a lot of hair, because there's no reason the load event should be firing.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    dascoli is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Posts
    16
    I thought the same thing! For the life of me I couldn't figure out why that was happening. It's even weirder that it only happens when the Navigation Bar and Ribbon are hidden. When I close it from the fully-loaded database it has no errors and closes perfectly. So weird!

    Again, thank you for replying so quickly to my post!

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    In my case it worked flawlessly as an Access 2000 mdb/mde, then when I upgraded it to a 2007 accdb/accde it did this. Drove me crazy, particularly since when I set a breakpoint and tried to step through the code, it threw the error before actually going to that point in the code. Made it hard to find. My forehead still hurts.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  2. Replies: 0
    Last Post: 07-16-2012, 05:42 AM
  3. Replies: 9
    Last Post: 06-08-2012, 07:52 AM
  4. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  5. error run time 2450
    By storm1954 in forum Forms
    Replies: 2
    Last Post: 05-11-2012, 06:05 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