Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727

    Disabling MDI window?


    I think it's called the MDI window but if not, I am referring to the window that is always behind my forms. It's the main Access window. I would like to either hide it or disable it somehow so that my database looks more clean and doesn't have that extra window to take up screen real estate. The other annoying part of this window is that I can't seem to control the property for the close button on it. If the user accidentally closes the MDI window, then it will also close the whole program which I do not want to happen. I only want the user to be able to close the program with my exit or log out buttons within the database forms. Does anyone know how to get this to work? Thanks.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    See if this discussion helps.

    Good luck.

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Hiding the app is cool but think I've seen discussions where it can be an issue if user minimizes. If you try it, would be interested in outcome.

    I use customized ribbon and code to disable the X close button. Review:
    https://www.accessforums.net/securit...bar-39781.html
    https://www.accessforums.net/access/...ers-48543.html
    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.

  4. #4
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Ok so I tried this out and it worked really great except for the minimizing of the screen. The best I could get so far was to put the calling of the function under the Detail section of the form and then under the Mouse Move event. This way it is always constantly minimizing the MDI window. The problem is that the cursor is always blinking with a loading circle because its constantly running the code. My other resolution for this whole problem would be just to disable the closing X button in the top right hand corner of the window itself. I just don't want users to accidentally close this window and it will also exit the database, saving the data that was entered regardless if the user wants to save it or not. All my code for prompts to ask the user if they want to save or not does not pop up nor does my prompt that asks the user if they are sure they want to exit the database. That is the main reason why I wanted to hide or get rid of that MDI window in the first place. Anyone got any ideas how to just disable the close option on the MDI window?

  5. #5
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Hey June 7,
    tried out your code for the disabling of the X close button but could not get it to work.

    I get an error on this line of code:


    lngMenu = GetSystemMenu(lngWindow, 0)

    Sub or Function not defined.

    Any idea what might be going wrong?


  6. #6
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Orange,

    in the discussion you provided the guys also explains that he has figured out a way to remove Access, when the program is open, from the taskbar at the bottom of the screen. This would also be a good feature to have since the user can click on Access in the taskbar to minimize and maximize the program. The guy in the discussion said he moved Access to the system tray instead which would be better than nothing since users tend to not look in the system tray as often. Does anyone know how to do this?

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Would have to review your code. Where did you put the code? Did you declare the API functions?

    I didn't originate the code. I found it. This might not have been my source but it looks very similar http://support.microsoft.com/kb/245746
    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.

  8. #8
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    I basically just pasted the x close section of the code in a module and was going to call it with your line of code to disable the x close button. Not sure what API is.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    API - Application Programming Interface http://en.wikipedia.org/wiki/Applica...ming_interface

    Need the API function declarations shown at the top of my example code and in the MS article.
    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.

  10. #10
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Sorry going back to the original subject for a moment, I found this code and it works really great except for one part. Check this out:

    [IMG]file:///C:\Users\data808\AppData\Local\Temp\msohtmlclip1\0 1\clip_image001.gif[/IMG]

    Access Hiding Access Background and Taskbar
    [IMG]file:///C:\Users\data808\AppData\Local\Temp\msohtmlclip1\0 1\clip_image002.gif[/IMG]
    Ease of Use Intermediate
    Version tested with 97, 2000
    Submitted by: ___
    Description: This code will completely hide the Access background and Access will not be visible on your taskbar OR task manager. WARNING: If you do not use this code correctly, you will need to restart your PC to open your Access application again.
    Discussion: This code can be used to make MS Access look like a 'stand alone' program. The main problem people have is not setting their forms to modal = yes and popup = yes. If you do not do this, Access will open but will not be visible anywhere on your PC.
    Code: instructions for use
    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

    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


    How to use:
    1. Make sure ALL your forms are set to Popup = Yes and Modal = Yes.
    2. Make sure that you have proper error handling in all your code.
    3. Copy the code above and insert it into a new module.
    4. In your form's 'OnLoad' event, do this: Call fSetAccessWindow(0)
    Test the code:
    1. Close and reopen your database

  11. #11
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    So the post above works perfectly if you set all forms to pop up and modal. However for reports this thing is not working properly. I have a report that opens from a button on a split form. The button that opens up the report has this code behind it:

    Dim strWhere As String
    If Me.Dirty Then Me.Dirty = False
    If Me.FilterOn Then strWhere = Me.Filter
    DoCmd.OpenReport "Created By_report", acViewReport, , strWhere
    Me.txtFilter.SetFocus

    The report is also modal. So when I open this report the split stays open in the background not being active till you close the report since the report is modal. However when I click the button that opens this report, nothing happens. The report does not appear and I lose focus from the split form that has the button I just clicked on to open the report. It's almost as if the report is somewhere and has the focus and since its modal, it won't let me have control of my split form, leaving me stuck with nothing I can click on or close. Does anyone know what I can do to fix this? I feel like I am soooo close to getting this to work as a stand alone program. You guys should really give this code a try and figure out how to get it working properly. I think a lot of people would be happy with this. Especially the fact that it not only hides the MDI window but it also hides it from the taskbar at the bottom of the screen.

  12. #12
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    I only want the user to be able to close the program with my exit or log out buttons within the database forms. Does anyone know how to get this to work? Thanks.
    Add the following code in a module and use fActivateControlBox(False) in the open event of the startup form to remove the close button
    Code:
    Option Compare Database
    Option Explicit
    
    Private Declare Function GetWindowLong Lib "user32" _
                    Alias "GetWindowLongA" _
                    (ByVal hwnd As Long, _
                    ByVal nIndex As Long) As Long
    
    Private Declare Function SetWindowLong Lib "user32" _
                    Alias "SetWindowLongA" _
                    (ByVal hwnd As Long, _
                    ByVal nIndex As Long, _
                    ByVal dwNewLong As Long) As Long
    
    Private Declare Function GetSystemMenu _
                    Lib "user32" _
                    (ByVal hwnd As Long, _
                    ByVal bRevert As Long) As Long
    
    Private Declare Function DrawMenuBar _
                    Lib "user32" _
                    (ByVal hwnd As Long) As Long
                   
    Private Declare Function DeleteMenu _
                    Lib "user32" _
                    (ByVal HMenu As Long, _
                    ByVal nPosition As Long, _
                    ByVal wFlags As Long) As Long
                   
    Private Const MF_BYCOMMAND = &H0&
    Private Const SC_CLOSE = &HF060
    
    Private Const WS_SYSMENU = &H80000
    Private Const WS_MAXIMIZEBOX = &H10000
    Private Const WS_MINIMIZEBOX = &H20000
    
    Private Const GWL_STYLE = (-16)
    
    Public Function fActivateControlBox(Enable As Boolean)
    Dim CurStyle As Long
    Dim hwnd As Long
    
        hwnd = Access.hWndAccessApp
    
        CurStyle = GetWindowLong(hwnd, GWL_STYLE)
        If Enable Then
            If Not (CurStyle And WS_SYSMENU) Then
                CurStyle = CurStyle Or WS_SYSMENU
            End If
        Else
            If (CurStyle And WS_SYSMENU) = WS_SYSMENU Then
                CurStyle = CurStyle - WS_SYSMENU
            End If
        End If
        Call SetWindowLong(hwnd, GWL_STYLE, CurStyle)
        Call DrawMenuBar(hwnd)
    
    End Function
    
    Public Function fActivateCloseBox(Enable As Boolean)
    Dim HMenu As Long
    Dim hwnd As Long
    
        hwnd = Access.hWndAccessApp
       
        If Enable Then
            Call GetSystemMenu(hwnd, True)
        Else
            HMenu = GetSystemMenu(hwnd, False)
            If HMenu Then
                Call DeleteMenu(HMenu, SC_CLOSE, MF_BYCOMMAND)
            End If
        End If
        Call DrawMenuBar(hwnd)
       
    End Function
    
    Public Function fActivateMaximizeBox(Enable As Boolean)
    Dim CurStyle As Long
    Dim hwnd As Long
    
        hwnd = Access.hWndAccessApp
    'Enable = False 'added by me
        CurStyle = GetWindowLong(hwnd, GWL_STYLE)
        If Enable Then
            If Not (CurStyle And WS_MAXIMIZEBOX) Then
                CurStyle = CurStyle Or WS_MAXIMIZEBOX
            End If
        Else
            If (CurStyle And WS_MAXIMIZEBOX) = WS_MAXIMIZEBOX Then
                CurStyle = CurStyle - WS_MAXIMIZEBOX
            End If
        End If
        Call SetWindowLong(hwnd, GWL_STYLE, CurStyle)
        Call DrawMenuBar(hwnd)
    
    End Function
    
    Public Function fActivateMinimizeBox(Enable As Boolean)
    Dim CurStyle As Long
    Dim hwnd As Long
    'Enable = False 'added by me
        hwnd = Access.hWndAccessApp
    
        CurStyle = GetWindowLong(hwnd, GWL_STYLE)
        If Enable Then
            If Not (CurStyle And WS_MINIMIZEBOX) Then
                CurStyle = CurStyle Or WS_MINIMIZEBOX
            End If
        Else
            If (CurStyle And WS_MINIMIZEBOX) = WS_MINIMIZEBOX Then
                CurStyle = CurStyle - WS_MINIMIZEBOX
            End If
        End If
        Call SetWindowLong(hwnd, GWL_STYLE, CurStyle)
        Call DrawMenuBar(hwnd)
    
    End Function

  13. #13
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Amrut,
    Thanks but just to clarify does this code work for the window in the back of the form? Because I have the control box property set to no already for all my forms. I just want the main access window that is in the background behind my forms to not have the close x button enabled.

  14. #14
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Yes, it disables the button to close database. See the screenshot of my application below. I have used buttons to minimize & quit.
    Click image for larger version. 

Name:	DisabledClose.jpg 
Views:	14 
Size:	8.4 KB 
ID:	19284

  15. #15
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    Ok I just tested amrut's code and it works wonderfully. I was wondering if you could assist with one last problem.

    So now that the MDI window close X button is gone. There is still another way a user is able to close the program outside of the user interface of the forms. If the user right clicks on access in the taskbar, a menu will pop up and give them the option to close window. What is the code to just hide access from the taskbar? I know the other code I posted does this and gets rid of the MDI window but like I mentioned earlier, that code messes up when I open a report. So I was wondering if I could still keep the MDI window open with the close X button disabled, but also hide the access program from just the taskbar.

    Is this possible?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 10-23-2013, 08:11 AM
  2. Disabling Fields
    By dolovenature in forum Programming
    Replies: 2
    Last Post: 09-16-2012, 07:45 PM
  3. Disabling fields
    By bursteffect in forum Access
    Replies: 1
    Last Post: 08-30-2012, 12:54 PM
  4. Disabling a control
    By NOTLguy in forum Forms
    Replies: 5
    Last Post: 10-31-2010, 11:34 AM
  5. Disabling A Button
    By cksm4 in forum Programming
    Replies: 8
    Last Post: 10-05-2010, 02: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