Results 1 to 12 of 12
  1. #1
    ssissons is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    May 2014
    Posts
    44

    Closing form, return contol to menu form


    I have an Access 2007 database with multiple forms, so I created a menu form. It calls the sub-forms correctly. But, when I want to exit the sub-form, I want control passed back to the menu. What is the command to do that? I have tried "DoCmd.Close" and "DoCmd.Close acform, Me.Name", but both completely close the DB, not just the form. If that is the right command, what parms do I use to close JUST the current form?

    Private Sub Exit_Click()
    DoCmd.Close acForm, Me.Name

    End Sub

  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,652
    Either of those should close just the form, so something else seems to be going on. Is there other code in the form that might be closing the db? No error message happens, it just closes the db?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I guess
    DoCmd.Close acForm, Me.Name
    will close the current form.

    I usually do this
    DoCmd.Close acForm, "FormName"

    If you have a form named frmMenu and you want to interact with it from another form's module, you could do something like this
    DoCmd.OpenForm "frmMenu"
    DoCmd.Close acForm, "FormName"

    even if frmMenu is already open, it will set focus on frmMenu. Because focus is on frmMenu, you need to be explicit and name the form you want to close. Docmd will default to the object with current focus if you do not explicitly tell it otherwise.

  4. #4
    ssissons is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    May 2014
    Posts
    44
    Quote Originally Posted by pbaldy View Post
    Either of those should close just the form, so something else seems to be going on. Is there other code in the form that might be closing the db? No error message happens, it just closes the db?
    No error message. And, that is the only Sub that closes the form.

  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,652
    Can you post the db here? That code shouldn't close the db.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    ssissons is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    May 2014
    Posts
    44
    Nope, that didn't work for me. Same results. Here is my code

    Private Sub Exit_Click()

    DoCmd.Openform "Menu"
    DoCmd.Close acForm, "LTCBACK_Entry"

    End Sub

  7. #7
    ssissons is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    May 2014
    Posts
    44
    Cant post the DB - company doesn't allow that.

  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,652
    Well, I'm not sure what to say. I have similar code in every db I've ever built, and it never closes the entire db. You need Quit to do that, so you may want to search for that in VBA. Failing that, you may have some sort of corruption.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Like Paul mentioned, something else is going on that is telling Access to quit. Maybe you have an embedded macro in your click event or whatever event you are writing your VBA in. An embedded macro will trump code in the VBA module.

    Somewhere, there is a .Quit method executing

  10. #10
    ssissons is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    May 2014
    Posts
    44
    I did a search through the DB - there were a couple of .QUIT statements, but not in the forms I was testing. I have now changed it so that the only .Quit is in the Menu form -- same result.

  11. #11
    ssissons is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    May 2014
    Posts
    44
    Sorry, guys. Apparently, my VB/Access skills have some serious holes. The buttons that are controlling what sub-form is executed had "Embedded Macro" in the On_Click event, and it was set to a different form than intended. I've got that all straightened out, and it is working correctly now. Thanks for your help!!

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Glad you got it sorted out.
    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: 1
    Last Post: 08-25-2013, 09:11 AM
  2. Editing form control except when closing form
    By EddieN1 in forum Programming
    Replies: 1
    Last Post: 07-26-2013, 05:22 PM
  3. Replies: 5
    Last Post: 12-22-2011, 01:12 PM
  4. Replies: 1
    Last Post: 03-07-2011, 10:48 AM
  5. Replies: 9
    Last Post: 02-15-2011, 03:05 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