Resizing Main Form When Sub-form is Hidden: How To?

vdanelia

Registered User.
Local time
Today, 03:40
Joined
Jan 29, 2011
Messages
215
Hello friends, I have a question about resizing the main window...
I have a form with controls : Text-Boxes, Combo-Boxes, Labels. Also I have a Sub-Form (Below of these controls) Which I'm showing and hiding with Check Box. As a matter of fact I'm not using the form always, but i need it...
When I hide a sub-form I want that the window minimized to near the other controls, because when hiding the Sub-form there is empty space below... and form looks ugly....
Thank you in Advanced
 
You should be able to check the recordcount of the subform (or the checkbox if you prefer the manual method or if the rowcount will always start at 0). If it is 0 you could then change the height of the subform control to 0 which would then allow you to alter the height of section.

This is assuming there is nothing else in line with or below the subform control.
 
Hello, Thanks for the reply..
Maybe I Explained incorrectly..

I have a form! A sub form on is, When i Hide sub form the place becomes empty (I mean the place where sub form was) and i want that when I'll hide sub-form The form size shrinked, when display sub-form the form must maximize....
 
Yes, I understand.

Assuming you want to keep the checkbox, I guess you currently have something like this:

Code:
If chkHideSubForm = true then
     me.SubFormControl.visible = false
Else
     me.SubFormControl = true
End if

This could be altered to:
Code:
If chkHideSubForm = true then
     me.SubFormControl.visible = false
     me.SubFormControl.height = 0
     me.Section.Height = 100 ' this will be the height without the subform, you will need to find out what this is
Else
     me.SubFormControl = true
     me.SubFormControl.height = 30 ' This iwill be the height of your subform when it is displayed, you will need to find out what this is
     me.Section.Height = 130 ' this will be the height with the subform, you will need to find out what this is
End if

:edit:

My code for section height may be off, the above is pseudocode.
 
Something went wrong, not working...
I'm Using Check-box Hiding/Showing Sub-Form with this code:

Me.ChForm.Visible = Me.CheckSF
 
I assume that's on the CheckSF after update / change event?

Try changing it to:

Code:
If CheckSF = false then
   me.ChForm.visible = false
   me.ChForm.height = 0
   me.Detail.Height = 100 ' this will be the height without the subform, you will need to find out what this is
Else
   me.ChForm= true
   me.ChForm.height = 30 ' This iwill be the height of your subform when it is displayed, you will need to find out what this is
   me.Detail.Height = 130 ' this will be the height with the subform, you will need to find out what this is
End if

I updated section to detail (my bad).

The heights of the subform and detail section is measures in twips. you will need to look at your form to work out what those values should be.
 
Error: It Says

Object doesn't support the property or method

and in yellow highlighted the code : Me.ChForm = True
 
sorry, the .visible dropped off the end when I replaced my placeholder subform name with the subform name you provided.

That line should read "Me.ChForm.Visible = True"
 
Code is working: The Sub-form is resizing, but the main form not :(
 
Instead of resizing the detail section you need to resize the form itself

do a search on below

DoCmd.MoveSize
 
It tried this and it works you just need to play with the sizes

Code:
Private Sub ChkHide_Click()

If Me.ChkHide = True Then
    Me.fsubform.Height = 0
    DoCmd.MoveSize , , , Me.InsideHeight - 2000
Else
    Me.fsubform.Height = 2000
    DoCmd.MoveSize , , , Me.InsideHeight + 2000

End If

End Sub

Making the subform invisible still leaves it the same size and Access will only resize the form upto the bottom of the subform. By making the subform size 0 you can recoup that space.
 
I Did The Best: :)
It Looks Like:

If Me!cmdShow.Caption = "Show >>" Then
Me!cmdShow.Caption = "Hide <<"
DoCmd.MoveSize , , , 10000
Me.SForm.Height = 3000
Else
Me!cmdShow.Caption = "Show >>"
DoCmd.MoveSize , , , 7000
Me.SForm.Height = 0

End If

Fully Functional!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom