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

    Popup form causes main form to close

    I have a popup form that when opened is causing the invoking form (main) to close. What might cause that?



    Code:
    Private Sub cmdHELP_Click()
    DoCmd.OpenForm "frmHELP", acNormal, , , , acDialog
    End Sub
    There are no events in the main form that get control where an explicit DoCmd.close would occur following the OpenForm of "frmHELP".

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    I assume there is code to close the popup. Explicitly name the form to close.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    The main form closes as soon as the popup opens. The main closes and the popup remains.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Are there events in frmHelp? Or in the main form's deactivate or lost focus event maybe?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Gra, you already told us what is happening. There has to be a why. And that means code somewhere.
    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.

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    "frmHELP"s code sheet. I don't see anything that would cause the caller to close.
    Code:
    Option Compare Database
    Option Explicit
    Dim strStepParms As String
    
    Private Sub Form_Open(Cancel As Integer)
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' Nominal position for the "How To" popup
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    
    XMoveSet = XMove                               'XMove is global
    fSetAccessWindow (SW_SHOWMINIMIZED)
    
    End Sub
    
    Private Sub Form_Load()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' Nominal position for the PC HELP scenario (User can override with form's set option)
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    
    DoCmd.MoveSize XMoveSet, 1000                  'Emperical positioning  (strStepParms is global)
    strStepParms = XMoveSet & ";" & Me.Width       'We need to tell the step forms our left offset and our width.
    
    End Sub
    
    Private Function OpenHelpNo(FormNo As Integer)
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    ' Popup line items will pass their identifier number here via their OnClick
    ' events.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim strFormName As String
    
    strFormName = "frmHelp-" & FormNo
    'DoCmd.OpenForm strFormName, , , , , , strStepParms
    
    End Function
        
    Private Sub lblCLOSE_Click()
    DoCmd.Close
    End Sub

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Don't see anything here either..............
    Code:
    Option Compare Database
    Option Explicit
     
    Global Const SW_HIDE = 0
    Global Const SW_SHOWNORMAL = 1
    Global Const SW_SHOWMINIMIZED = 2
    Global Const SW_SHOWMAXIMIZED = 3
     
    Private Declare Function apiShowWindow Lib "user32" _
    Alias "ShowWindow" (ByVal hWnd As Long, _
    ByVal nCmdShow As Long) As Long
    
    Public Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
        (ByVal filename As String, ByVal snd_async As Long) As Long
        
     
    Function fSetAccessWindow(nCmdShow As Long)
         
        Dim loX As Long
        Dim loForm As Form
        On Error Resume Next
        Set loForm = Screen.ActiveForm
         
        If Err <> 0 Then
            loX = apiShowWindow(hWndAccessApp, nCmdShow)
            Err.Clear
        End If
         
        If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
            MsgBox "Cannot minimize Access with " _
            & (loForm.Caption + " ") _
            & "form on screen"
        ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Then
            MsgBox "Cannot hide Access with " _
            & (loForm.Caption + " ") _
            & "form on screen"
        Else
            loX = apiShowWindow(hWndAccessApp, nCmdShow)
        End If
        fSetAccessWindow = (loX <> 0)
    End Function

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Well, for some reason the DoCmd.Close is closing the main form, not the popup. Try explicitly naming the popup form.

    DoCmd.Close acForm, "frmHelp", acSaveNo
    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.

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    June,
    Your post suggests that you think the main form closes when I close the popup. It appeared that the main form closed when I OPENED the popup. I implemented you explicit close of "frmHELP" anyway just to be sure. I am now seeing that the main form IS NOT closing but rather it's Minimizing, so it's a different problem but symptomatically the same, i.e., main form "disappears" when I Open the popup.

  10. #10
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Really weird Paul. Here's some code from the main form that opens the "Settings" popup. It works exactly as would be expected. I've looked at the offending popup at least 20 times I can't for the life of me see what it is about its Opening that would cause the main form to suddenly minimize.

    Code:
    Private Sub imSettings_Click()
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Click on the settings "gear".  Be prepared to update the display (Main Form) if user changes the
    '  setting that dictates the number of rows per column.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim intTemp As Integer
    
    intTemp = DLookup("NumRows", "tblSettings", "SettingsID = 1")
    
    DoCmd.OpenForm "frmSettings", acNormal, , , , acDialog
    
    intBlkSz = DLookup("NumRows", "tblSettings", "SettingsID = 1")
        If intTemp <> intBlkSz Then
            bolReOpen = True
            DoCmd.Close
        End If
        
    End Sub

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Haven't used it, but noticed:

    fSetAccessWindow (SW_SHOWMINIMIZED)

    Have you tried commenting that out?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Hi Bill

    See attached for an example database that uses similar code & will hopefully explain what's happening.
    I've deliberately included code to show you how easy it is for the intended results to go wrong

    The example app has 2 popup forms: Form1 & Form 2
    It opens at Form1 with the application window visible
    Click the button to open form 2 & 'hide' the application window. Its actually minimized to the taskbar (but don't click the taskbar icon YET)
    This also means Form1 disappears though its not been closed

    From Form2 return to Form1 - I've added code to restore the application window & you'll see Form2 is still visible.
    Both forms are now open & visible - DELIBERATE PROBLEM - neither form button now works!
    However, after 3 seconds another button appears to allow Form2 to be closed. Click it.

    Now you have Form1 ONLY open. Click to open Form2 again & hide Form1 & application window.
    Now click the taskbar icon - the app window is restored along with Form1
    BUT the timer event isn't triggered so the Close Form2 button remains hidden. OOPS!!!!

    2Forms&AppWindow.zip

    A more realistic example of how the application window can be hidden & restored properly can be found here: http://www.mendipdatasystems.co.uk/c...ace/4594365418
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Replies: 2
    Last Post: 11-22-2015, 07:24 PM
  2. Replies: 6
    Last Post: 07-16-2014, 12:18 PM
  3. Replies: 4
    Last Post: 01-20-2013, 06:34 PM
  4. Replies: 11
    Last Post: 01-10-2013, 06:23 PM
  5. Replies: 1
    Last Post: 02-29-2012, 09:38 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