Results 1 to 8 of 8
  1. #1
    JB510's Avatar
    JB510 is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Ontario
    Posts
    42

    Problem closing a form.

    I have a bunch of code to update Excel, send email, update records etc ..


    At the end I give the command

    Code:
    DoCmd.Close ObjectType:=acForm, ObjectName:="Build1F"
    DoCmd.OpenForm "MainMenuF"
    To close the form and open the main menu.

    I am getting an error "This action can't be carried out while processing a form or report event."

    There are no other forms open and I am not calling up more than the subroutine it is running in.
    How do I get around this?

    (It is working in other forms)

  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
    Two shots in the dark. Add DoEvents between the lines or reverse the order of your two lines.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    JB510's Avatar
    JB510 is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Ontario
    Posts
    42
    Quote Originally Posted by pbaldy View Post
    Two shots in the dark. Add DoEvents between the lines or reverse the order of your two lines.
    Tried reversing.. it will process the
    Code:
    DoCmd.OpenForm "MainMenuF"
    but the
    Code:
    DoCmd.Close ObjectType:=acForm, ObjectName:="Build1F"
    it don't like. - Same error

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,943
    I think you might need to show the code before it?
    Quick trst would be comment out all code before those two lines and see if that works.
    Do the easy stuff first.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    JB510's Avatar
    JB510 is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Ontario
    Posts
    42
    Sorry for the delay but thank you.
    Issue solved.
    I commented all the code out and it still failed to close..
    Problem was the command
    Code:
    DoCmd.Close ObjectType:=acForm, ObjectName:="Build1F
    did not work..

    I replaced it with
    Code:
    DoCmd.Close
    Totally frustrating....

  6. #6
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    The most reliable way to close the current form (and not some other arbitrary object) is

    Code:
      DoCmd.Close acForm, Me.Name
    This uses the current forms name, so can't really go wrong.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    JB510's Avatar
    JB510 is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Ontario
    Posts
    42
    My apologies'... it was because the close command was in a
    Code:
    xxxxx_LostFocus ()
    event.

    It did not like it. I had to change it to a
    Code:
    xxxxxx_AfterUpdate()
    event.

  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
    That makes more sense, thanks for the update. I typically use Minty's method too.
    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. Closing a form
    By nevertool8 in forum Forms
    Replies: 3
    Last Post: 06-13-2019, 09:07 AM
  2. Closing a pop-up form?
    By drharb in forum Forms
    Replies: 3
    Last Post: 11-15-2016, 06:34 PM
  3. Replies: 6
    Last Post: 01-06-2015, 12:37 PM
  4. Closing a form through VBA
    By ghostmachine in forum Forms
    Replies: 4
    Last Post: 12-13-2010, 01:57 PM
  5. Closing a Form Problem
    By MuskokaMad in forum Forms
    Replies: 2
    Last Post: 03-18-2010, 05:58 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