Solved Changing Form's width (1 Viewer)

KitaYama

Well-known member
Local time
Today, 20:13
Joined
Jan 6, 2022
Messages
1,541
I have a problem with changing a form's width and hope someone can shed a light.
(I hate long questions, But I couldn't make this post shorter. Sorry.)
This is a simple form in design view:

1.png


Two buttons and a checkbox. I change the width of the form on OnOpen event to something that is not enough to show all the controls.

Code:
Me.InsideWidth = 600

Since form's orientation is set to Left-To-Right, I expect Access start from X=0 Y=0 (left top of the form) and show 600 twips width of the form.
But it's no actually what happens. Here's what I have.

22.png


As you can see, Access cuts the left side too.
By clicking the checkbox, I change the size again, but still less than what the form needs to show all objects.
And as you see, again Access seems to trim both sides, not only the right side.

3.png


Does anyone know how to prevent Access to cut the left side too?

Why I need this:
I have a form with several subforms. There's a checkbox that users can tick to show/hide the subform on the right side of the form if they don't need it.
the next time the form opens, OnOpen event of the main form, checks for user's last situation and change the width of the form to hide the subform.
In this case, the left side of the form is cut off too.

A sample file is attached.

Thanks for any kind of solution.
 

Attachments

  • Database2.accdb
    1.1 MB · Views: 67

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:13
Joined
Feb 28, 2001
Messages
27,186
Surely it would be easier to use the memory of that "Hide me" checkbox to just make the parts you don't want to see become .Visible=FALSE?

But... as an experiment, what happens if you drag the checkbox to the other side of its label? Does it cut off in the same way? Checkboxes are a bit funny when compared to other controls because the checkbox's actual size is hard to change, probably due to an unknown quirk in the black box that is Access.

And then there is the question of whether "Layout" options are still enabled when you diddle with the form's width. Last time I played with Layout, I finally got frustrated and disabled it.
 

KitaYama

Well-known member
Local time
Today, 20:13
Joined
Jan 6, 2022
Messages
1,541
Surely it would be easier to use the memory of that "Hide me" checkbox to just make the parts you don't want to see become .Visible=FALSE?
Hiding the subform leaves a lot of blank space at the right side of the form. The balance is terrible and it doesn't look nice.
If I don't find a solution, I prefer to have two main form and delete the subform from one of them and show one of them per users' option.

But... as an experiment, what happens if you drag the checkbox to the other side of its label? Does it cut off in the same way?
Yes, The label will be cut off. As you can see in second image above, the button is cut off too.

And then there is the question of whether "Layout" options are still enabled when you diddle with the form's width. Last time I played with Layout, I finally got frustrated and disabled it.
No, Layout view is disabled.

Thanks for trying to help.
 

Edgar_

Active member
Local time
Today, 06:13
Joined
Jul 8, 2023
Messages
430
In the debugger, I see that the .Width property of the form is 7256. If you want the full form, maybe you should use that property to get the size.
 

KitaYama

Well-known member
Local time
Today, 20:13
Joined
Jan 6, 2022
Messages
1,541
In the debugger, I see that the .Width property of the form is 7256. If you want the full form, maybe you should use that property to get the size.
As I explained, I need the form to be less than its actual width to hide a subform in the right.
My question is why Access cuts of the left side too.

To the best of my knowledge, objects are drown from left, up to what the width is set to in property sheet or in vba.
(In Left to right orientation)
If you change the width of a button in vba, the left side is intact and only the right side is cut off.
I wonder why it's not the same for forms.

Thank you.
 
Last edited:

Edgar_

Active member
Local time
Today, 06:13
Joined
Jul 8, 2023
Messages
430
I see something different
1698904198240.png

As you can see, it does not cut the edge. If you play with the inside with of your On Load event, you'll see that this effect is reduced when the window fits the entire control. There's something trying to center the view.
 

Edgar_

Active member
Local time
Today, 06:13
Joined
Jul 8, 2023
Messages
430
If you change the border style to Sizable, the edges are normal.
 

KitaYama

Well-known member
Local time
Today, 20:13
Joined
Jan 6, 2022
Messages
1,541
There's something trying to center the view.
Yes, I've noticed that. If I set the width of the form more than 1500 twips, the left side is OK.
What I uploaded, is just something simple to show the effect.
My real form, just like any other form, has a lot of controls and each one has a different width. When I open the form, more than 1/3 of the form width of the form is cut from the left side. I think it's because of the different width of the controls and as you noticed, Access is trying to center the widest one.

I just wanted to see anyone has a solution.
Thanks again.
 

KitaYama

Well-known member
Local time
Today, 20:13
Joined
Jan 6, 2022
Messages
1,541
If you change the border style to Sizable, the edges are normal.
If I change the border style in my sample database in #1, the problem is solved.
But my main form, still suffers from the same effect.
Maybe it's because of I have a tab control at the left. Or a rectangle that I've used to separate some objects.

I'll play a little to see if I can track which control is causing the problem.

Thank you.
 

Edgar_

Active member
Local time
Today, 06:13
Joined
Jul 8, 2023
Messages
430
What's centering the view is the control with focus, if you press the tab key, it will change your view. So that's probably the culprit.
 

KitaYama

Well-known member
Local time
Today, 20:13
Joined
Jan 6, 2022
Messages
1,541
What's centering the view is the control with focus
I disabled all controls and set their locked property to Yes, to be sure nothing have the focus.
Still the same effect.

I'm not sure what causes this effect, but since my sample file's problem was solved by @Edgar_ in #7, and I'm not allowed to share our database, I think the culprit is one of objects/controls in the left side of our form, hence I accept the given solution as the correct answer and mark this thread as solved.

The first 10 users from shop floor were not excited about a change in form's design, so I gave up the idea of form's design change.
You know how some users are. Change the position of a button and they can't do their job.

I was able to solve the problem in a stupid way, that I hate.
So for now, the problem's solved. Though any more idea is much appreciated.
 

KitaYama

Well-known member
Local time
Today, 20:13
Joined
Jan 6, 2022
Messages
1,541
The solution I chose :

The order of form's events : Open - Load .....

In Open event I set the width of the form to the maximum width it needs to show all controls correctly
In Load event I read the user's option and if the sub forms needs to be not shown, I change the width accordingly.

Well, for now it works.

thanks to all.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 12:13
Joined
Sep 12, 2006
Messages
15,656
@KitaYama

I know you marked this solved, but I often use this in the form open event

RunCommand acCmdSizeToFitForm

which makes the form large enough to display the full form design.
There's a few similar size to fit commands, but I am not sure precisely what they do offhand.

I also often save the position and size of forms so when they open, I can restore them to their last appearance. That way I only have to resize a new form once.
 

KitaYama

Well-known member
Local time
Today, 20:13
Joined
Jan 6, 2022
Messages
1,541
I know you marked this solved, but I often use this in the form open event
What I ended to was a dirty way to bypass the problem. So still any kind of idea/advice is much appreciated.
I tested both Open & Load events, but the result was the same.

RunCommand acCmdSizeToFitForm

which makes the form large enough to display the full form design.
My current problem is the opposite. The problem occurs when the width of the form is less than the actual size.
So acCmdSizeToFitForm can not be used in this case.

There's a few similar size to fit commands, but I am not sure precisely what they do offhand.
I'll do a research on this to see if I find something that can suit the situation. Thanks.

I also often save the position and size of forms so when they open, I can restore them to their last appearance. That way I only have to resize a new form once.
Then on every opening of a form you need to read do co-ordinates from a table and move the form.
Why not setting autoResize and AutoCenter properties to yes? Do you often open the forms not in the center of the screen?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 12:13
Joined
Sep 12, 2006
Messages
15,656
What I ended to was a dirty way to bypass the problem. So still any kind of idea/advice is much appreciated.
I tested both Open & Load events, but the result was the same.


My current problem is the opposite. The problem occurs when the width of the form is less than the actual size.
So acCmdSizeToFitForm can not be used in this case.


I'll do a research on this to see if I find something that can suit the situation. Thanks.


Then on every opening of a form you need to read do co-ordinates from a table and move the form.
Why not setting autoResize and AutoCenter properties to yes? Do you often open the forms not in the center of the screen?

How can the width be less than the actual size, unless the detail is hidden for instance? I don't understand that. If that is the case when you make the component visible, you can then resize the form to fit. acCmdSizeToFitForm opens to the size of the forms background irrespective of components. It can give you an issue with the height of a continuous form, though, but not the width.

I used code from the Access Cookbook to store and restore forms. That also included code to resize controls when anchored against sides of a form. At the time that wasn't part of Access. Presumably MS liked the idea, and built it into Access. I just continued to use my code, as I already had a library with the functions.

I don't want to resize and centre every form. My app might open 5 or 6 forms at startup, and the users can decide which forms, and have them sized and positioned to suit their own layout, not all sized to full form display.

I don't like tabbed forms. I much prefer overlapping, although I often provide an option to let users decide.

I also have a small popup form that shows all the open forms, and that can be used to select and give the focus to any form, even if it's hidden under other forms. The menu switchboard, for example.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 12:13
Joined
Sep 12, 2006
Messages
15,656
Is there any way you can upload a sample for me to see the issue?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 12:13
Joined
Sep 12, 2006
Messages
15,656
Yes, thanks.

The problem seems to to be that the main form is set up as a dialog form, so you can't resize it other than in code.
Make it sizable instead, and you should be OK.

With this as the form load event, it opens to your full size, even as a dialog form.

Private Sub Form_Load()
RunCommand acCmdSizeToFitForm
' Me.InsideWidth = 1000
End Sub

and this code on the button click resizes the form, even if it opens at the small size.

Private Sub Command1_Click()
RunCommand acCmdSizeToFitForm
End Sub
 
Last edited:

Users who are viewing this thread

Top Bottom