Results 1 to 6 of 6
  1. #1
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904

    Closing a Form with a Command Button

    I have an old 2003 (mdb) Access database that I am working on (I currently have Access 2007). We still have some users who use Access 2003, so we have not updated/converted it yet (the database is split into back/front-ends).

    I have created a few new forms. First, I have a Selection Form where the users enters in the criteria to bring up their particular clients data. In then opens up a Continuous Form for data entry. I placed a Close/Exit command button in the Form Footer. If I use the Command Button Wizard for this buton, it creates the following code:
    Code:
    Private Sub cmdClose_Click()
    On Error GoTo Err_cmdClose_Click
    
        If Me.Dirty Then Me.Dirty = False
        DoCmd.Close
    Exit_cmdClose_Click:
        Exit Sub
    Err_cmdClose_Click:
        MsgBox Err.Description
        Resume Exit_cmdClose_Click
        
    End Sub
    When I first created it, it worked. But now when we try to use this button, we get the following error message:
    The expression On Click you entered as the event property setting prodcued the following error: A problem occurred while Microsoft Office Access was communicating with the OLE server or ActiveX Control.


    *The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure].
    *There may have been an error evaluating the function, event, or macro.
    I tried simplying my code to these variations, but it made no difference:
    Code:
     
    Private Sub cmdClose_Click()
        DoCmd.Close
    End Sub
    Code:
     
    Private Sub cmdClose_Click()
        DoCmd.Close acForm, Me.Name
    End Sub
    I have searched the internet, and found various posts on the topic, but haven't found one yet that seems to apply to my situation.

    I should also add, if they just click on the "X" in the upper right-hand corner, the form closes without issue. It just doesn't seem to like the Close/Exit command button anymore.

    Any ideas?

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Since your code has absolutely nothing to do with any ActiveX Controls, my guess would be that the Command Button has become corrupted! While we usually thinks in terms of Forms or entire Databases becoming corrupted, Controls can and do become corrupted, as well. I'd replace the errant button and use your original code.

    Linq ;0)>

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    A good thought. I failed to mention that I already tried creating a brand new command button to close the form, and that new button returned the same error. So that does not seem to fix it.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Is it possible for the Form itself to become corrupt, or the VB module itself?
    I tried adding a new command button somewhere else on the form that simply returns a Message Box with the phrase "Hi", and that returns the same error.
    So I think the issue is on a bigger scale, related to the Form itself or VBA module.

  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Yep, it looks like the VBA Module itself became corrupted. We removed all the VBA code, copied the form to a new name, and then recreated the buttons, and it worked.

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by JoeM View Post
    ...I tried adding a new command button somewhere else on the form that simply returns a Message Box with the phrase "Hi", and that returns the same error.
    The fact that another button returned the same error is proof that the corruption is more widespread than the one Control. But the best approach is to start checking out the easiest to replace first and then move out to Form and then the database itself!

    Glad you got it working again!

    Linq ;0)>

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

Similar Threads

  1. Replies: 9
    Last Post: 08-06-2011, 02:10 PM
  2. Use a command button to open a form
    By johnpaul in forum Forms
    Replies: 24
    Last Post: 09-23-2010, 12:29 PM
  3. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  4. Export Command Button in Form
    By jjmartinson in forum Forms
    Replies: 3
    Last Post: 08-25-2009, 01:28 AM
  5. Adding Command Button To Form
    By uneek78 in forum Forms
    Replies: 7
    Last Post: 03-27-2009, 07:43 PM

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