Solved Form layout: 2 subforms filling the form for 50% each (1 Viewer)

Martin123

New member
Local time
Today, 17:51
Joined
Jun 23, 2023
Messages
2
Hi there, this is my first post! I have some experience managing an Access project (including the VBA code behind it), but it's mainly self-taught. I use the Access version from Microsoft 365.

My question: Is it possible to scale two subforms in one form equally, so that they'll each take up 50% of the screen (one on the left side, and one on the right side)? The idea is to have the parent data on the left, and when the user selects a row, the subform on the right will show the data that is part of that parent. Both subforms would be datasheet views. I know it's possible to have the two subforms, but I can't get the alignment to work. None of the anchoring options in the arrange tab seem to get to the wanted behaviour.

I also tried this using VBA, where you could set the left and width properties during the Form_Load (and later on in the Form_Resize) events. However, Form.Width is not the full width of the screen as it turns out since it repositions the widgets but not where i want them.

Code:
Private Sub Form_Load()
    With Me.leftSubform
      .Left = 0
      .Width = Form.Width / 2
    End With
    
    With Me.rightSubform
      .Left = Form.Width / 2
      .Width = Form.Width / 2
    End With
End Sub

What am I missing?

Thanks in advance :D
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:51
Joined
May 7, 2009
Messages
19,245
inspect the InsideWidth property of the form and do it in the Resize event of the form to resize your subform.
 

Josef P.

Well-known member
Local time
Today, 17:51
Joined
Feb 2, 2023
Messages
826
Tip: use layout + anchor => works without code
 

Attachments

  • SubFormsFillMainForm.zip
    18.1 KB · Views: 69

CJ_London

Super Moderator
Staff member
Local time
Today, 16:51
Joined
Feb 19, 2013
Messages
16,614
Is it possible to scale two subforms in one form equally, so that they'll each take up 50% of the screen
Just be aware that many screens are much wider than the maximum width of a form (22”) so if your form is maximised you will get an error.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:51
Joined
May 7, 2009
Messages
19,245
i also use the Vertical Anchor of the two subforms.
and again i use the Main form's Resize event to resize the two subforms and re-establish the Left property of subform 2.

there are two samples 1 is pop-up and the other is not.
 

Attachments

  • EqualLeftRightSubfrm.accdb
    640 KB · Views: 75

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:51
Joined
May 7, 2009
Messages
19,245
Tip: use layout + anchor => works without code
it will work when you make the main form large.
but when you drag it to make it smaller, the problem arises.
 

Josef P.

Well-known member
Local time
Today, 17:51
Joined
Feb 2, 2023
Messages
826
If you design the main form in the smallest size to be used, it will run without problems.
A size of the main form of 1x1cm probably nobody will want to use.

If it needs to be more flexible, you can always react to the resize event.
But sometimes the simple variant is enough. ;)
 
Last edited:

Martin123

New member
Local time
Today, 17:51
Joined
Jun 23, 2023
Messages
2
Hi guys, thanks for the quick responses! I currently fixed it using the insideWidth property as suggested by @arnelgp! This seems to work for my use case. I didn't know this property existed.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:51
Joined
May 7, 2009
Messages
19,245
i forgot to upload another 2 forms that has small equal margins on each side of the subforms.
just a demo (forms, 21popUpWithMargins and 22NotpopUpWithMargins)
 

Attachments

  • EqualLeftRightSubfrm.accdb
    596 KB · Views: 73

Users who are viewing this thread

Top Bottom