Microsoft KB Archive/103261

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 12:24, 21 July 2020 by X010 (talk | contribs) (Text replacement - "&" to "&")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

ACC1x: How to Remove the Caption Bar from a Form


The information in this article applies to:

  • Microsoft Access versions 1.0, 1.1


There is no built-in mechanism in Microsoft Access version 1.x for removing the caption bar from a form. The caption bar runs across the top of the window and includes the Control menu and the minimize and maximize buttons.

Microsoft Access version 2.0 has properties you can use to remove the minimize and maximize buttons and the Control menu. For more information, search for "MinButton, MaxButton, and ControlBox" using the Help menu in Microsoft Access 2.0. Or you can set the BorderStyle property to None to remove the caption bar from the form.

This article demonstrates a sample user-defined Access Basic function called RemoveCaptionBar() that you can use to remove the caption bar from a form. Procedures for creating a form with no caption bar are also listed.

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual.


Creating a New Module to Delete Caption Bar

NOTE: In the following sample code, an underscore (_) is used as a line-continuation character. Remove the underscore when re-creating this code in Access Basic.

NOTE: You may have some Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive the duplicate procedure name error message when you compile or run your code, remove or comment out the appropriate declarations statement.


   Option Explicit

   ' Windows API Rect structure
   Type RECT
       x1 As Integer
       y1 As Integer
       x2 As Integer
       y2 As Integer
   End Type

   ' Windows API Declarations
   Declare Function SetWindowLong& Lib "User" (ByVal hwnd%, _
                    ByVal iindex%, ByVal style&)
   Declare Function GetWindowLong& Lib "User" (ByVal hwnd%, _
                    ByVal iindex%)
   Declare Function GetSystemMetrics% Lib "User" (ByVal iIndex%)
   Declare Function GetWindowRect% Lib "User" Alias "GetWindowRect" _
                    (ByVal hwin%, rectangle As RECT)
   Declare Function MoveWindow% Lib "User" Alias "MoveWindow" _
                    (ByVal hwin%, ByVal x%, ByVal y%, ByVal dx%, _
                    ByVal dy%, ByVal fRepaint%)

   ' GetWindowLong Constants
   Const GWL_STYLE = -16

   ' Window Styles Constants
   Global Const WS_CAPTION = &HC00000

   ' System Metrics Constants
   Global Const SM_CYCAPTION = 4

   ' FUNCTION: RemoveCaptionBar
   '   Removes the caption bar, which includes the system menu
   '   and minimize and maximize buttons, from a form.
   '   F - The form object from which to remove the caption bar.
   ' USAGE:
   '   Enter the following for the OnOpen property of a form called
   '   MyForm:
   '       =RemoveCaptionBar(Forms![MyForm])
   '   With a normal form, the form opens slightly lower than
   '   expected. With a dialog form (PopUp=Yes, Modal=Yes), the form
   '   opens slightly higher than expected. Also, you cannot close the
   '   form using the Microsoft Access menu; you must close it
   '   programmatically.
   '   If the form property Popup=No, a form is created that has a
   '   sizable border. Since Captions are required for sizable windows,
   '   screen painting problems may occur. For instance, if the frame
   '   of the Window is a light color, the division lines for the frame
   '   will display, creating an undesirable effect.
   Function RemoveCaptionBar (F As Form)
       Dim OldStyle As Long, NewStyle As Long
       Dim R As RECT
       Dim RetVal As Integer
       Dim dx As Integer, dy As Integer

       ' Get the current window style of the form.
       OldStyle = GetWindowLong(F.hwnd, GWL_STYLE)

       ' Set the window style to be the same, minus the caption bar.
       NewStyle = OldStyle And Not WS_CAPTION

       'Change the window style of the form.
       OldStyle = SetWindowLong(F.hwnd, GWL_STYLE, NewStyle)

       ' The caption is removed, but the border has not snapped down
       ' .. onto the smaller window. We will call the Windows API to
       ' .. move and size the window to the same location and size,
       ' .. with the window shortened by the length of the caption bar.
       RetVal = GetWindowRect(F.hwnd, R)
       dx = R.x2 - R.x1
       dy = R.y2 - R.y1 - GetSystemMetrics(SM_CYCAPTION)
       RetVal = MoveWindow(F.hwnd, R.x1, R.y1, dx%, dy%, True)
   End Function 

Creating a Form with No Caption Bar

The following instructions show how to create a form that does not have a caption bar:

  1. Create or open a database in Microsoft Access.
  2. Create a new, blank, unbound form and save it with the name NoCaption.
  3. Change the OnOpen property of the form to read:


  1. From the View menu, choose Form.

Additional query words: menu bar

Keywords : kbprg
Issue type : kbhowto
Technology :

Last Reviewed: November 4, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.