View Full Version : Position and Size the Access Window


ajetrumpet
05-28-2009, 04:03 PM
Here is some code that will enable you to position and size the Microsoft Access Window accordingly.

Declarations Section:Declare Function apiMoveWindow Lib "User32" Alias "MoveWindow" _
(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 apiGetActiveWindow Lib "User32" Alias "GetActiveWindow" () As Long
Declare Function apiGetParent Lib "User32" Alias "GetParent" (ByVal hWnd As Long) As LongFunctions to Use:Function AccessMoveSize(iX As Integer, iY As Integer, iWidth As _
Integer, iHeight As Integer)

apiMoveWindow GetAccesshWnd(), iX, iY, iWidth, iHeight, True

End Function

Function GetAccesshWnd()

Dim hWnd As Long
Dim hWndAccess As Long

hWnd = apiGetActiveWindow()
hWndAccess = hWnd

While hWnd <> 0
hWndAccess = hWnd
hWnd = apiGetParent(hWnd)
Wend

GetAccesshWnd = hWndAccess

End FunctionCall the function to move and size the window with:Call AccessMoveSize('X' axis pos, 'Y' axis pos, Width, Height)The only time I have personally used this function is when I wanted to completely hide and disable the MS Access window from being viewed. Combining the above code with "check screen resolution" code will move the access window off the screen so it is inaccessible to users. For example, to reduce the size of the window to 0 length x 0 width, and move it off the screen to the right-hand side for a computer with a screen resolution of 1024 x 768, call the above function with:Call AccessMoveSize(1024, 0, 0, 0)This code does not apply to multiple monitor setups. I have attached an illustration of checking the screen resolution and using these functions to move the access window off the right side of the screen. Any comments welcome. :)