Set Minimum size for a form

Hi,

I have a main form which is maximized to the Access window.
The access window is set to a certain size when the form is opened, but the size can be changed.
I would like to stop users making the access window (and hence the form) smaller than the first size it is opened at.

I have tried using the API calls suggested in other threads, but it just goes into a sort of loop and doesn't respond to anything.

Please help!

Janine
janineoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

damiaanCommented:
dim w as long
dim h as long
Private Sub Form_Load()
 w = me.width
 h = me.height
End Sub

Private Sub Form_Resize()
    if me.height < h then me.height = h
    If Me.Width < w Then Me.Width = w
End Sub


(or was it Me.WindowHeight  /    me.WindowWidth ?)

kind regards
0
damiaanCommented:
or set your bordersize to thin

in form_load:
Me.BorderStyle = 1
0
janineoAuthor Commented:
Sorry, this isn't what I need.
It works on the form, but when the Access Window itself is sized, it seems to overule the form settings.

Maybe I didn't explain myself properly.
When I say Access Window, I do not mean the Database Window, but the instance of Access itself in which all the other windows sit, and to which the menus are attached.

I have a main form that opens when my Access mdb is opened. This form has no border and is maximized to the Access Window. The Access Window is then sized programmatically to what will be it's minimum size.
I need to stop the Access Window getting any smaller. Stopping a form getting too small has no effect on the Access Window.

Please tell me if this is even possible!
Janine
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

gwgawCommented:
Add variables to your main form's declaration section.

Dim accWidth As Long
Dim accHeight As Long

Set accWidth or accHeight to Access window size on form open.

In the form's on timer event check if accWidth or accHeight is equal to 0. If they are then get  Access window size into variables and exit sub.

If they are greater than 0 then get Access window size and compare to these variables and resize Access window as needed. You may also want to check if Access is minimized or maximized and react accordingly.

gaw
0
damiaanCommented:
>Please tell me if this is even possible!
don't know about gwgaw's solution.  
but with api's it will be possible!
0
damiaanCommented:
my guess is

Public Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long

Public Declare Function GetWindowPlacement Lib "user32" Alias "GetWindowPlacement" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

and SetWindowRect / SetWindowPlacement
...

good luck!
0
gwgawCommented:
To maintain Access window position and size.

Add this to your main form's declaration section. Set the form's TimerInterval to 100.

Dim rcAcc As RECT

Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

Private Const SW_MAXIMIZE = 3
Private Const SW_MINIMIZE = 6

Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Type WINDOWPLACEMENT
    Length As Long
    flags As Long
    showCmd As Long
    ptMinPosition As POINTAPI
    ptMaxPosition As POINTAPI
    rcNormalPosition As RECT
End Type

Form open and timer events.

Private Sub Form_Open(Cancel As Integer)
Dim WP As WINDOWPLACEMENT
'Get Access position and size into rcAcc
WP.Length = Len(WP)
GetWindowPlacement Application.hWndAccessApp, WP
rcAcc = WP.rcNormalPosition
End Sub

Private Sub Form_Timer()
Dim rc As RECT, WP As WINDOWPLACEMENT
Dim lgWid As Long, lgHgt As Long
WP.Length = Len(WP)
'Get Access position and size
GetWindowPlacement Application.hWndAccessApp, WP
'If Access is maximized or minimized then quit
If WP.showCmd = SW_MAXIMIZE Or WP.showCmd = SW_MINIMIZE Then Exit Sub
'Check if rcAcc has been set
If rcAcc.Right = 0 Or rcAcc.Bottom = 0 Then
    rcAcc = WP.rcNormalPosition
    Exit Sub
End If
WP.rcNormalPosition = rcAcc
SetWindowPlacement Application.hWndAccessApp, WP
End Sub

gaw
0
gwgawCommented:
Here's another way.

Place this in form's declaration section

Dim lgStyle As Long

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 Const GWL_STYLE = (-16)
Private Const WS_BORDER = &H800000
Private Const WS_THICKFRAME = &H40000

Then in form's open and unload events.

Private Sub Form_Open(Cancel As Integer)
Dim dl As Long
'Get Access window style and change border style to allow no sizing
dl = GetWindowLong(Application.hWndAccessApp, GWL_STYLE)
dl = (382664704 And Not WS_THICKFRAME Or WS_BORDER)
lgStyle = SetWindowLong(Application.hWndAccessApp, GWL_STYLE, dl)
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim dl As Long
'Reset Access window style
dl = SetWindowLong(Application.hWndAccessApp, GWL_STYLE, lgStyle)
End Sub

gaw
0
janineoAuthor Commented:
gwgaw,
Thanks, but this isn't quite what I'm after. Your first solution allowed a user to make the form smaller than the minimum, and then sprang it back to the minimum after they let go of the mouse. The second solution didn't allow the user to make it larger, which I do want to allow.
Is there a way of combining them, so the user can make it bigger, but not allow the form size to move with the mouse after a minimum size has been reached?

I can use the GetWindowPlacement function to get the size of the window at the beginning.
I just need somewhere to put some code so that the minimum size is not gone past.
Is the 'ptMinPosition As POINTAPI' in the WINDOWPLACEMENT type a minimum size, or a minimum position where the top left of the window can go?

Damiaan,
I couldn't find a SetWindowRect API call. Can you provide one for me?

Thank you,
Janine
0
gwgawCommented:
>Is the 'ptMinPosition As POINTAPI' in the WINDOWPLACEMENT type a minimum size, or a minimum position where the top left of the window can go?<

No

ptMinPosition
Specifies the coordinates of the window's upper-left corner when the window is minimized.
ptMaxPosition
Specifies the coordinates of the window's upper-left corner when the window is maximized.
rcNormalPosition
Specifies the window's coordinates when the window is in the restored position.

There is no SetWindowRect api.

Take a look at this one.
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=8281&lngWId=1

gaw
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
janineoAuthor Commented:
That's a great link, gwgaw!
Just what I wanted.
Thanks!
Janine
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.