Results 1 to 15 of 15
  1. #1
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81

    DoCMD.Close not always working

    I have a command isn't working. It is a simply command to close the current form.
    Code:
     Private Sub Command14_Click()
                    DoCmd.Close
               End Sub
    In order for me to close out this form I can't use the close button associated with command14. I have to right click on the form and go to design view. There is always another form opened behind it that is the main form for the program. Any ideas why the code doesn't work?

  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,521
    Close will close the active object. You can be specific:

    DoCmd.Close acForm, Me.Name
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81
    I tried that code as well. It still doesn't close. Any other ideas?

  4. #4
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81
    I created a new form and copied that layout over. That button still refuses to work. My current code is
    Code:
    Private Sub Command14_Click()
       DoCmd.Close  acForm, Me.Name
    End Sub

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Are you sure the code is associated with the button? Make sure it says "Event Procedure" in the click event property of the button, and that clicking on the ellipsis takes you to that code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81
    Quote Originally Posted by pbaldy View Post
    Are you sure the code is associated with the button? Make sure it says "Event Procedure" in the click event property of the button, and that clicking on the ellipsis takes you to that code.

    Yes, I went to the design view o of the form. The button is called close. I view the code and that is what came up. I change it to the active form but it doesn't work. It also doesn't work to use the X to close out the form either. So must be some type of corruption. Perhaps I should delete out that button in it entirety and redo it. Either that or the form is corrupt

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you attach the db here to play with?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  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,521
    By the way, you said the button was called "Close", but the event is associated with "Command14".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81
    If I right click on the form and pick close nothing happens. But it I right click on the form and say close all then both forms close; however, I only want the one form to close out. If the form is the only form open then the close button works just fine.

  10. #10
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81
    That is just the label on the button. The event is Command14. It seems to be hung up then when the Main form of the survey program is opened behind it.

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you attach it here? Might be something with popup/modal settings, but it would be nice to be able to play with it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81
    How is it something so simple can cause grief. When the form opens the code to open the form had GotFocus instead of click. That was preventing it from closing.

    So it was
    Code:
     Private Sub Sommand28_GotFocus()
    DoCmd.OpenForm "PreRep"
    End Sub
    I simply changed the GotFocus to click and now it works
    Would there be any reason to keep the GotFocus?
    I really should take some access programming classes. Any suggestions?

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I can't imagine a use for the focus event of a button. Presumably you want the user to click it when they're ready, not have it execute just because they tabbed until they got to the button or something.

    I'm not sure of any classes. I went to the school-of-hard-knocks.

    Steve Bishop has youtube videos that I've heard are pretty good.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81
    Thank you for your time and help! I really appreciate it. Perhaps I will simply take some VBA classes. I'm self taught as well.

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    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. DoCmd Close Query Not Working
    By bfont in forum Programming
    Replies: 2
    Last Post: 04-16-2020, 03:25 PM
  2. VBA code after DoCmd.Close acForm
    By Miles R in forum Forms
    Replies: 9
    Last Post: 04-11-2020, 03:28 PM
  3. DoCmd.Close not working as expected
    By GraeagleBill in forum Programming
    Replies: 7
    Last Post: 12-07-2016, 12:31 AM
  4. DoCmd.Close Not Working
    By kdbailey in forum Access
    Replies: 6
    Last Post: 12-11-2013, 07:35 PM
  5. DoCmd.Close OpenArgs NOT WORKING
    By clchris_80 in forum Access
    Replies: 1
    Last Post: 01-19-2013, 09:07 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