Results 1 to 4 of 4
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095

    DoCmd.Close not working as expected (From 12-6-2016!)

    I knew there was something familiar about the error I hit today, see post number 5:



    https://www.accessforums.net/showthread.php?t=63255

    I had to add "Exit Sub" to my code before I could get the form to close without coughing on the remaining statements in the OPEN code. One might have to suspect that I've discovered yet another of my life's nemesis?

    Code:
    Private Sub Form_Open(Cancel As Integer)
    
    If Me.RecordsetClone.RecordCount = 0 Then
        MsgBox "There are no ""un-cleared"" deposits to show."
        DoCmd.Close acForm, Me.Name
        Exit Sub
    End If
    
    strLastReconcile = Me.OpenArgs
    Me.lblLR.Caption = "(Beginning with date: " & strLastReconcile & ")"
    Me.ChkCleared.SetFocus
    
    End Sub

  2. #2
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    Yes, the remaining code of a form will execute if you don't exit - even if you cancel the open event. Odd, I know. However, if you cancel the event you don't need DoCmd.Close, but you still need to exit to prevent other code from being executed.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095
    It does seem odd that execution of subsequent code continues as though nothing else had been directed. Sort of like kids when you tell them to stop what they're doing.
    Thanks,
    Bill

  4. #4
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    Quote Originally Posted by GraeagleBill View Post
    It does seem odd that execution of subsequent code continues as though nothing else had been directed. Sort of like kids when you tell them to stop what they're doing.
    Thanks,
    Bill
    LOL! Nice analogy
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. DoCMD.Close not always working
    By Canadiangal in forum Programming
    Replies: 14
    Last Post: 10-21-2020, 07:08 PM
  2. DoCmd.Close not working as expected
    By GraeagleBill in forum Programming
    Replies: 7
    Last Post: 12-07-2016, 12:31 AM
  3. DoCmd.OpenForm with OpenArgs not working as expected
    By equestrian in forum Programming
    Replies: 6
    Last Post: 09-08-2015, 01:32 PM
  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