Results 1 to 8 of 8
  1. #1
    alextijuca is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2015
    Posts
    6

    close Form from within a Form.current event


    The following statement doesn't work within a Form.current event:
    DoCmd.Close acForm, Me.Name, acSaveYes


    What could I do to achieve this action ?

    Thank you in advance

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Why would you want to close a form from its Current event?

    What does "doesn't work" mean - error message, wrong results, nothing?

    What is the complete procedure code?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    In Access 2010, you can't close a form while you are running a form-level event (you get an error message), and On Current is a form-level event.

    I assume A2000 is the same.

    Tell us what you are trying to do, so we can offer some suggestions.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Open event has argument to allow canceling form open. That is probably the only place form can be 'closed' at form level - if condition is met the form doesn't open, user doesn't even see it.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    alextijuca is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2015
    Posts
    6
    As John_G said, I get an error message saying operation is not possible.
    I have a number of registers that I can create and, when that finishes, I have to come out of the form.current event back to the initial form. So my first thought was to write a command that did that.

    I will try the Open event suggested by June 7 and see what happens. In the event, I will display a message to the user saying he cannot create more registers.

    Any other suggestion will be welcomed.

    Thank you all.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    How will code in Open event help you get 'back to the initial form' after data entry is completed? Form can be closed by code in button Click or a control AfterUpdate events.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    alextijuca is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2015
    Posts
    6
    Hi,

    I have noticed that I can come out from the form by writing a docmd.close instruction in the Form.Open event, by testing a condition. However, the flow of the program moves to the Form.current event before closing the form. I expected that it would just finish the present event (Form.Open) e return to the previous Form.

    Does anyone know a command for not passing through the Form.corrent event as above described ?

    Thank you

  8. #8
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Instead uf using Docmd.close, cancel the On open event by setting Cancel = -1

    if your test condition fails.

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

Similar Threads

  1. Replies: 3
    Last Post: 01-14-2015, 02:51 PM
  2. Replies: 4
    Last Post: 10-09-2014, 07:09 PM
  3. Replies: 7
    Last Post: 05-08-2014, 10:34 AM
  4. Replies: 4
    Last Post: 01-31-2014, 11:47 AM
  5. Replies: 2
    Last Post: 06-20-2011, 03:10 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