Open access-application with fixed size

  • Thread starter Thread starter reidarT
  • Start date Start date
You certainly can, I forget where I saw the link. The only link I can find
at the moment is to hide the Access Window completely, or make it
maximised: find that at http://www.mvps.org/access/api/api0019.htm

If I remember what the other link was I will post it on here.

Cheers

John Webb
 
Hi Reidar

The following procedure (with associated declarations) will size the Access
application window. It first restores it if it is maximized, then resizes
it. The second argument (height) is optional and if you don't provide it,
the procedure calculates the appropriate default 4:3 aspect ratio. For
example,
SizeAccessWindow 800
is equivalent to
SizeAccessWindow 800, 600

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

========== start code ===========
Private Declare Function IsZoomed Lib "user32" _
(ByVal hWnd As Long) _
As Long

Private Declare Function ShowWindow Lib "user32" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) _
As Long

Private Const SW_SHOWNORMAL = 1

Private 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

Public Sub SizeAccessWindow(ByVal lPixelsX As Long, Optional ByVal lPixelsY
As Long)
Dim hWnd As Long
If lPixelsY = 0 Then lPixelsY = lPixelsX * 3 / 4
hWnd = Application.hWndAccessApp
If IsZoomed(hWnd) Then
ShowWindow hWnd, SW_SHOWNORMAL
End If
MoveWindow hWnd, 0, 0, lPixelsX, lPixelsY, True
End Sub
=========== end code ============
 
I am trying to open Access with a popupform in front an access window hide.
I use code from Dev Ashish. I have made a module and placed the code in it.
I can not use the word Global before the constant.
If I remove the word Global and only use Const, I can debug the application.
If I call this function from a popup-form it stops on the line
?fSetAccessWindow(SW_HIDE)



Here is the code

************ Code Start **********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
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)
'Usage Examples
'Maximize window:
' ?fSetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
' ?fSetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
?fSetAccessWindow(SW_HIDE)
'Normal window:
' ?fSetAccessWindow(SW_SHOWNORMAL)
'
Dim loX As Long
Dim loForm As Form
On Error Resume Next
Set loForm = Screen.ActiveForm
If Err <> 0 Then 'no Activeform
If nCmdShow = SW_HIDE Then
MsgBox "Cannot hide Access unless " _
& "a form is on screen"
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
Err.Clear
End If
Else
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
End If
fSetAccessWindow = (loX <> 0)
End Function

'************ Code End **********
 
Hi Reidar

It sounds like you have those four constants declared in another module.
Try just commenting out the lines entirely and see if it compiles.
 
Back
Top