Results 1 to 5 of 5
  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 ignored

    Related to thread: https://www.accessforums.net/showthread.php?t=86127

    Main app form needs to obtain conditional formatting values to set global variables from a form currently not open. So, the main form opens the required form (frmSchedule) just enough to set the variables and then close. The problem is that the DoCmd.Close seems to be ignored. Does the form need to "Load" before it can be closed?



    Code:
    
    Private Sub Form_Open(Cancel As Integer)
    
    
    If Me.OpenArgs = "Just Colors" Then
        '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
        '  Apps main form needs to know what colors are currently being used with
        '  periods.  Set global variables accordingly and close.
        '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
        Me.Visible = False
        lngClrWakeup = Forms!frmSchedule.tbPeriod.FormatConditions(0).BackColor
        lngClrBreakfast = Forms!frmSchedule.tbPeriod.FormatConditions(1).BackColor
        lngClrLunch = Forms!frmSchedule.tbPeriod.FormatConditions(2).BackColor
        lngClrDinner = Forms!frmSchedule.tbPeriod.FormatConditions(3).BackColor
        DoCmd.Close acForm, "frmSchedule"
    End If
    
    
    Me.Visible = True
    intDetailHt = Me.Section(acDetail).Height
    
    
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,906
    Why do you use Forms!frmSchedule for the CF and not for the close?
    Have you tried Me.Name
    Could even perhaps call the Close event as well, if even for a test.

    Edit:
    FWIW this worked for me in Form1, so have you walked through the code?

    Code:
    Private Sub Form_Open(Cancel As Integer)
    If Not IsNull(Me.OpenArgs) Then
        Me.Combo16 = Me.OpenArgs
    End If
    MsgBox "Form " & Me.Name & " is closing"
    DoCmd.Close acForm, "Form1"
    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

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    so have you walked through the code?
    Oh yes, always before OP.

    What happens is that the OnLoad runs before the DoCmd.close takes effect, then the form in fact closes.

    EDIT: Also ignores Call cmdCLOSE_Click, but the the OnOpen continues to execute and bombs when attempting to execute "intDetailHt = Me.Section(acDetail).Height".

    What is working is to issue an "Exit Sub" after the DoCmd.Close. While that essentially resolves the OP, it doesn't make sense to me that code in the OnOpen continues beyond the close?

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    Let's see if I grasp what you're doing:
    - opening a form which has open or load event and in that event you are opening a second form
    - in the 2nd form open or load event you are trying to close the 1st form
    - you are wondering why any code in the 1st form that hasn't executed is still processing even though you demanded that it close?

    If that's correct, then it is to be expected. Unless you have some sort of abnormal close of either the db or crash of a form, don't expect unfinished code to terminate just because you initiate a close command from somewhere else. This behaviour is commonly reported when someone cancels a form open event and the form that called it complains that the event was cancelled. If memory serves, that is error 2501?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    you are trying to close the 1st form
    No, the first form (Main) is opening the 2nd form for the sole purpose of obtaining CF color properties known ONLY to the 2nd form, after which it closes the 2nd form. My downfall stemmed from my false belief, as you pointed out, that the close would terminate further execution. All I had to do to resolve this issue is to "Exit Sub" after the close.

    As for the CF issue, I must confess that what I would normally do is as June7 mentioned in that with having arrived at a point in development where color values could be captured that one could then simply put public constants in one's global module and access as needed. However, the issue became somewhat academic and I chose to deal with the CF color values in a purely dynamic fashion. That is, the 2nd form referenced here is the controlling form in the sense that it is the defining source of colors and all other forms in the app MUST conform. With how I've implemented the app, the main form obtains the current color values and sets global variables available to all in order to maintain conformity.

    Colin has some color-picker apps and NOW THAT I KNOW HOW to set CF color properties in code I would likely take a different approach in setting the colors were I to start anew.

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

Similar Threads

  1. DoCmd.Close
    By markjkubicki in forum Programming
    Replies: 3
    Last Post: 02-13-2021, 12:00 PM
  2. DoCMD.Close not always working
    By Canadiangal in forum Programming
    Replies: 14
    Last Post: 10-21-2020, 07:08 PM
  3. DoCmd Close Query Not Working
    By bfont in forum Programming
    Replies: 2
    Last Post: 04-16-2020, 03:25 PM
  4. VBA code after DoCmd.Close acForm
    By Miles R in forum Forms
    Replies: 9
    Last Post: 04-11-2020, 03:28 PM
  5. DoCmd.Close Not Working
    By kdbailey in forum Access
    Replies: 6
    Last Post: 12-11-2013, 07:35 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