Autosize subform

E

erick-flores

Hello all

I know this question has been asked million times, but I just can not
figure out the right correct way to do it. This is my scenario:
Form A (Single form) and Form B (Datasheet view).
Form B is a subform in Form A.

I want to be able to maximaze both Form A and B when I open Form A. Of
course right now its only maximizing Form A. Form B will not do
anything. I have changed the properties on the form but no luck. I
tried downloading an .mde, paste all the codes to my forms and no
luck. I do not know what to do, I REALLY need some help here.

The problem is managers have this big monitors and they want to be
able to look at the datasheet view (Form B) in a bigger size.

Any ideas of how to maximize a subform when the form opens???


Thanks in advance
 
R

Rick Brandt

erick-flores said:
Hello all

I know this question has been asked million times, but I just can not
figure out the right correct way to do it. This is my scenario:
Form A (Single form) and Form B (Datasheet view).
Form B is a subform in Form A.

I want to be able to maximaze both Form A and B when I open Form A. Of
course right now its only maximizing Form A. Form B will not do
anything. I have changed the properties on the form but no luck. I
tried downloading an .mde, paste all the codes to my forms and no
luck. I do not know what to do, I REALLY need some help here.

The problem is managers have this big monitors and they want to be
able to look at the datasheet view (Form B) in a bigger size.

Any ideas of how to maximize a subform when the form opens???

There is only ONE form here that can be sized and that is obviously the
parent. What you are calling a "subform" is actually a control (just like a
TextBox) and just as maximizing a form is not going to do anything to the
size of the TextBoxes on that form neither is it going to affect the size of
the subform control.

You CAN though change the size of a control in response to the Resize event
of the main form and thus make the subform control grow and shrink based on
the size of the main form. This is easiest if the control you want to
resize has no other controls under it or to the right of it.

In the Resize event code of the main form you can determine the new size of
the parent window by looking at the InsideHeight and InsideWidth properties.
Then you simply do some math to determine what the new size of the subform
control should be.

But...there is a complication. When you resize the main form (or maximize
it) you are not actually changing the size of the form at all. You are only
changing the size of the window. Assuming that your subform control is
sitting in the detail section of the main form you will first have to make
the section taller/wider, then you can make the subform control
taller/wider. When the window is made smaller you have to reverse the
order, first making the subform shorter/narrower and then making the form
section shorter/narrower. Try to do these out of order and you will get an
error.

This means you need variables to hold the OLD width and height so you can
compare them to the new width and height to determine the direction of the
size change.

A further complication is that the width comes form the form's sections and
the height comes from the form itself and if your fomr has headers or
footers then you will have to subtract those from InsideHeight when you do
your calculations.

I know it sounds horrendous, but if broken up into individual steps it
really is not that bad. I do this with a lot of my forms mostly for exacly
what you want, to see more subform records when the form is made taller.
 
G

Guest

Hi

You should tell the managers that's not what a sub form does - of course you
can make it bigger (open the main form in design view and drag the sub form
to the size you want then save). But - a sub form is just that it's a "sub".
You really shouldn't maximise it over the whole screen (well you"could")
but then what would be the point - you would be better simply opening
(filtered) it as a new form After/SomeEvent on the other form.
 
E

erick-flores

Thanks for your reply. I perfectly understand what I mean but I don't
know how to implemented. In other words what kind of code do I need?
do you have some examples available so I can use then as a guide?

Thanks in advance
 
E

erick-flores

What about some code that determines the resolution of the monitor.
Based on the resolution open the form in a certain way (bigger or
smaller). I dont know if this can be done...or how difficult is to get
it to work. I am just thinking on some ideas.

I need to able to switch depending on the resolution because the same
database is used by different monitors.
 
R

Rick Brandt

erick-flores said:
What about some code that determines the resolution of the monitor.
Based on the resolution open the form in a certain way (bigger or
smaller). I dont know if this can be done...or how difficult is to get
it to work. I am just thinking on some ideas.

I need to able to switch depending on the resolution because the same
database is used by different monitors.

Actually you should not. People with larger monitors running higher resolutions
do no want to see the same program windows only larger. They want to see MORE
stuff at one time. If you make the changes that allow the subform to grow as
the main form is resized then people with higher res monitors will automatically
be able to see more records than those with lower res monitors because they will
be able to make the main form larger relative to font size.
 
R

Rick Brandt

erick-flores said:
Thanks for your reply. I perfectly understand what I mean but I don't
know how to implemented. In other words what kind of code do I need?
do you have some examples available so I can use then as a guide?

Thanks in advance

Simple example when making the form taller/shorter. Lets say the subform is
normally one inch (1440 twips) tall and the InsideHeight of the form is normally
4 inches (5760 twips) tall. That means the subform is a tall as the forms
InsideHeight - 4320 twips. So if I make the main form taller/shorter the resize
event would be similar to.

Me.SubformControlName.Height = Me.InsideHeight - 4320
 
E

erick-flores

Simple example when making the form taller/shorter. Lets say the subform is
normally one inch (1440 twips) tall and the InsideHeight of the form is normally
4 inches (5760 twips) tall. That means the subform is a tall as the forms
InsideHeight - 4320 twips. So if I make the main form taller/shorter the resize
event would be similar to.

Me.SubformControlName.Height = Me.InsideHeight - 4320

I can not get this to work. I must be doing something wrong. This is
what I am doing:

On Resize Event in my main form I tried: Forms![All-details].Height =
Me.InsideHeight - 4320
and nothing happend. I got an error saying: "can't find the form 'All-
details' referred to in..."

What do I need to do? remenber my subform is in Datasheet view.


Thanks in advance
 
E

erick-flores

Actually you should not. People with larger monitors running higher resolutions
do no want to see the same program windows only larger. They want to see MORE
stuff at one time.
Yes, you are right they want to see more data.
If you make the changes that allow the subform to grow as
the main form is resized then people with higher res monitors will automatically
be able to see more records than those with lower res monitors because they will
be able to make the main form larger relative to font size.
Yes this is what I want
 
R

Rick Brandt

erick-flores said:
Simple example when making the form taller/shorter. Lets say the
subform is normally one inch (1440 twips) tall and the InsideHeight
of the form is normally 4 inches (5760 twips) tall. That means the
subform is a tall as the forms InsideHeight - 4320 twips. So if I
make the main form taller/shorter the resize event would be similar
to.

Me.SubformControlName.Height = Me.InsideHeight - 4320

I can not get this to work. I must be doing something wrong. This is
what I am doing:

On Resize Event in my main form I tried: Forms![All-details].Height =
Me.InsideHeight - 4320
and nothing happend. I got an error saying: "can't find the form 'All-
details' referred to in..."

What do I need to do? remenber my subform is in Datasheet view.


Thanks in advance

Remember you are changing the size of a *control* on the main form, not the
size of the form shown inside the subform control. When that inner form is
in continuous or datasheet view its vertical size doesn't matter. It will
automatically show however many rows the height of the subform control will
allow.

Just use the syntax in my previous example substituting the name of your
subform control (which is not guaranteed to have the same name as the form
inside).
 
E

erick-flores

I finally got it to work, I was just using the wrong syntax

Thank you very much Rick

:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top