I just recently needed to be able to hide the Access window in a quickie
access app. The app had just one form which was used to log events an keep
track of time during the day. The customer wanted the form to always be
visible an positioned to the upper right hand corner of the screen. They
wanted the from to be as small as possible, and did not want any other
windows to be visible.
What I would up doing was to make my one and only form an Access popup from.
It is also the Access start up form. So when Access starts my form loads.
My form calls a sub that moves it to the upper right hand corner and then
moves and resizes the Access MDI window to the same coordinates, directly
underneath my form. End result is it appears that the Access MDI window has
disappeared.
Here is the function that does the deed:
Public Sub UpperLeftPopupUp(f As Form)
' Purpose Puts the Form f in the Extreme Top Right of the screen if it is
an
' Access Popup form. Populates the PMDIRect Rect Structure with
the inital
' placement of the Access MDI window before it moves it under the
Popup form f.
Dim FrmRect As RECT
Dim RetVal As Long
If f.PopUp = False Then
Exit Sub
End If
' If the form is maximized, restore it.
If IsZoomed(f.hWnd) <> 0 Then
RetVal = ShowWindow(f.hWnd, SW_SHOWNORMAL)
End If
' Get the screen coordinates and window size of the MDIClient window.
RetVal = GetWindowRect(GetParent(f.hWnd), PMDIRect)
RetVal = GetWindowRect(f.hWnd, FrmRect)
' Move the form to the UpperRight Corner of the Screen
RetVal = MoveWindow(f.hWnd, _
(GetSystemMetrics(SM_CXFULLSCREEN) - (FrmRect.Right -
FrmRect.Left)), _
(0), _
FrmRect.Right - FrmRect.Left, _
FrmRect.Bottom - FrmRect.Top, _
True)
' Move Access Directly underneath out popup form (Access appears to be
minimized)
RetVal = MoveWindow(hWndAccessApp, _
(GetSystemMetrics(SM_CXFULLSCREEN) - (FrmRect.Right -
FrmRect.Left)), _
(0), _
FrmRect.Right - FrmRect.Left, _
FrmRect.Bottom - FrmRect.Top, _
True)
End Sub
You will need the following Declares in the same module.
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, _
lpRect As RECT) As Long
Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, _
ByVal nCmdShow As Long) As Long
Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, _
ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As
Long
' Show Window Constants
Const SW_MAXIMIZE = 3
Const SW_SHOWNORMAL = 1
' System Metrics Constant
Const SM_CYCAPTION = 4
Const SM_CXFULLSCREEN = 16
Const SM_CYFULLSCREEN = 17
The only "problem" I had with this setup was if I called Call
UpperLeftPopupUp(me) from the form load event occasionally I would crash
Access. What I wound up doing was setting the timer to 100ms and calling
the code from the OnTimer event thusly:
Private Sub Form_Timer()
If Me.TimerInterval <= 110 Then
' Runs this code one time only just to position the form
' in the upper Left Hand Corner of the screen at Start Up
Me.TimerInterval = 0
Call UpperLeftPopupUp(Me)
End If
End Sub
Apparently Access is not done doing at it has to do by the time the start up
form was loading. Waiting a tenth of a second after form load allows enough
time for Access to get itself stabilized.
Sooo.... By all means use the link that Brian provided if it makes sense,
but here is another possible way to get the deed done if you have at least
one form you want to have displayed.
Ron W