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

    DoCmd.Close not working as expected

    Did something change going from A2010 to A2013 regarding DoCmd.Close? Case in point:



    Code:
    If Me.RecordsetClone.RecordCount = 0 Then
        MsgBox "There are no eBud (Reserved) accounts" & vbNewLine & _
               "assocated with the current register."
        DoCmd.Close
    End If
    The segment of code is in the OnOpen Sub of a form that I want to close after having notified the user there's nothing to look at. The message displays but the DoCmd.Close seems to be ignored.

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    it's always better to be clear about what is being closed, so suggest complete the object type and name parameters to docmd.close

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I agree with Ajax.

    I use "DoCmd.Close acForm, Me.Name"

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Yes, I should have mentioned that I'd tried that without success. (Even tried the form name without quotes)

    Code:
    If Me.RecordsetClone.RecordCount = 0 Then
        MsgBox "There are no eBud (Reserved) accounts" & vbNewLine & _
               "assocated with the current register."
        DoCmd.Close acForm, "frmAccounts"
    End If

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Hmmmm, I just tested your code and it works for me.

    I set the query for the record source so that there were no records returned. The message box displayed and the form did not open/display.

    Set the query so that records were returned. The form opened without the message box....
    I used
    Code:
    Private Sub Form_Open(Cancel As Integer)
        If Me.RecordsetClone.RecordCount = 0 Then
            MsgBox "There are no eBud (Reserved) accounts" & vbNewLine & _
                   "assocated with the current register."
            DoCmd.Close acForm, Me.Name
        End If
    End Sub

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    OMG! I'm almost too embarrassed to tell you what I did.

    DoCmd.Close acForm, Me.Name works perfectly.................. when one inserts the code into the code sheet of the "correct" form! Two entirely different forms with similar names. (My excuse is having had a sleep study last night and too impaired today to be doing anything requiring serious thought.)

  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,518
    But isn't it fun trying to sleep with 100 wires attached to you and a camera watching?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Not in the least!

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

Similar Threads

  1. DoCmd.OpenForm with OpenArgs not working as expected
    By equestrian in forum Programming
    Replies: 6
    Last Post: 09-08-2015, 01:32 PM
  2. Not Like statement not working as expected
    By nick404 in forum Queries
    Replies: 4
    Last Post: 07-20-2015, 03:02 PM
  3. DoCmd.Close Not Working
    By kdbailey in forum Access
    Replies: 6
    Last Post: 12-11-2013, 07:35 PM
  4. Movelast not working as expected
    By GraeagleBill in forum Programming
    Replies: 28
    Last Post: 08-04-2013, 01:37 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