Results 1 to 4 of 4
  1. #1
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694

    Disable App Close button in 2007

    all,

    I have even posted a FAQ about this at AWF, but apparently my code does not work in 07. I can google "ms access hide close button" and get many good leads, but they all end up giving similar code, which is what is in my FAQ as well. I know it works for pre-07's, but can anyone test it out in their own versions of 07? I'm wondering if my copy of Access or office is corrupt (running 07 of course). thanks!



    Here is a link to my own code that I tested in the past on 03:

    http://www.access-programmers.co.uk/...t=close+button
    (I've only gotten this code to disappear the minimize button, it does nothing for the max or close buttons)

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    If anyone has 2007 and is willing to test some code for me, I'd appreciate it. The code for 03 versions are all over the internet, but it does nothing for my 07 version. Can someone test this in their own version? Certain would appreciate it!

    Code:
    ' ********** Code Start *************
    Option Explicit
    
    Private Const GWL_STYLE = (-16)
    Private Const WS_CAPTION = &HC00000
    Private Const WS_MINIMIZEBOX = &H20000
    Private Const WS_MAXIMIZEBOX = &H10000
    Private Const WS_SYSMENU = &H80000
    
    
    Private Const SWP_NOSIZE = &H1
    Private Const SWP_NOMOVE = &H2
    Private Const SWP_NOZORDER = &H4
    Public Const SWP_FRAMECHANGED = &H20
    
    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 SetWindowPos _
    Lib "user32" ( _
    ByVal hwnd As Long, _
    ByVal hWndInsertAfter As Long, _
    ByVal X As Long, _
    ByVal Y As Long, _
    ByVal cx As Long, _
    ByVal cy As Long, _
    ByVal wFlags As Long _
    ) As Long
    ' **************************************************
    '
    
    Function AccessTitleBar(Show As Boolean) As Long
    Dim hwnd As Long
    Dim nIndex As Long
    Dim dwNewLong As Long
    Dim dwLong As Long
    Dim wFlags As Long
    
    hwnd = hWndAccessApp
    nIndex = GWL_STYLE
    wFlags = SWP_NOSIZE + SWP_NOZORDER + SWP_FRAMECHANGED + SWP_NOMOVE
    
    dwLong = GetWindowLong(hwnd, nIndex)
    
    If Show Then
    dwNewLong = (dwLong Or WS_CAPTION)
    Else
    dwNewLong = (dwLong And Not WS_CAPTION)
    End If
    
    Call SetWindowLong(hwnd, nIndex, dwNewLong)
    Call SetWindowPos(hwnd, 0&, 0&, 0&, 0&, 0&, wFlags)
    End Function
    
    
    Function Buttons(Show As Boolean) As Long
    Dim hwnd As Long
    Dim nIndex As Long
    Dim dwNewLong As Long
    Dim dwLong As Long
    
    hwnd = hWndAccessApp
    nIndex = GWL_STYLE
    
    Const wFlags = SWP_NOSIZE + SWP_NOZORDER + SWP_FRAMECHANGED + SWP_NOMOVE
    Const FLAGS_COMBI = WS_MINIMIZEBOX Or WS_MAXIMIZEBOX Or WS_SYSMENU
    
    dwLong = GetWindowLong(hwnd, nIndex)
    
    If Show Then
    dwNewLong = (dwLong Or FLAGS_COMBI)
    Else
    dwNewLong = (dwLong And Not FLAGS_COMBI)
    End If
    
    Call SetWindowLong(hwnd, nIndex, dwNewLong)
    Call SetWindowPos(hwnd, 0&, 0&, 0&, 0&, 0&, wFlags)
    End Function
    ' ********** Code End *************
    TO DISABLE:
    Call Buttons(false)

    TO ENABLE:
    Call Buttons(True)

  3. #3
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Hey ajetrumpet,

    I'm curious about this. I have both 2003 and 2007 and 2010. I'd like to test this but I got a few errors when copying/pasting the code you supplied and then debugging/compiling. Could you perhaps post a 2003/2007 version of the actual mdb/accdb's themselves?

    Since I use a different technique (I maximize a 'background' form on startup) and then open/utilize popup/modal forms (this disables all the MSAccess Menus and prevents a user from clicking on them), I don't deal with the same issue but I'd like to experiment with this since I'm interested in this technique.

    This is the error line when pasting into 2003/2007:

    Public Const SWP_FRAMECHANGED = &H20

    Here's the technique I use: https://www.accessforums.net/code-re...html#post30756 which works in all versions of MSAccess.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by pkstormy View Post
    Hey ajetrumpet,

    I'm curious about this. I have both 2003 and 2007 and 2010. I'd like to test this but I got a few errors when copying/pasting the code you supplied and then debugging/compiling. Could you perhaps post a 2003/2007 version of the actual mdb/accdb's themselves?

    Since I use a different technique (I maximize a 'background' form on startup) and then open/utilize popup/modal forms (this disables all the MSAccess Menus and prevents a user from clicking on them), I don't deal with the same issue but I'd like to experiment with this since I'm interested in this technique.

    This is the error line when pasting into 2003/2007:

    Public Const SWP_FRAMECHANGED = &H20

    Here's the technique I use: https://www.accessforums.net/code-re...html#post30756
    I discovered this too. We simply used the technique that you did. I believe though that POPUP properties combined with maxed forms can disappear the Title Bar completely (no need for both mode and popup). I resorted to this because I tired of experimenting with code that's obviously geared for pre-2007 versions only.

    I don't think the code is relevant to the type of file, only to the version of access you have. The reason I think this is because the ribbon is the big difference between 07 and pre's.

    For instance, the COMMANDBARS collection includes the MENU BAR in 00,03,07 versions. The controls in the menu bar contain every option that you can see in the dd menus of 03 versions and earlier ... AND VBA's execution of them are all exactly what is executed by using interface clicking. BUT ... they are moved to the RIBBON in 07, and believe it or not, the commandbars("RIBBON").controls collection count in 07 is ZERO!

    Unbelievable...I really think that's part of the problem with the code posted in this thread (if not the entire problem).

    I've tried everything I can think of to locate the position of that close button - hwnd, ribbon bar index number, etc... I'm gonna let it go for now, but if you ever find a snippet to access that thing, I sure would like to know!

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

Similar Threads

  1. Replies: 15
    Last Post: 04-11-2015, 08:15 AM
  2. Add a close button?
    By thestappa in forum Reports
    Replies: 1
    Last Post: 07-15-2010, 10:43 AM
  3. Close Button Functions
    By Evgeny in forum Programming
    Replies: 3
    Last Post: 04-29-2010, 11:21 PM
  4. Replies: 4
    Last Post: 09-10-2009, 03:09 AM
  5. how to disable command button
    By archie in forum Access
    Replies: 1
    Last Post: 08-27-2009, 11:11 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