Form and SubForm-Control resizing to fit Form contained in SubForm-Control

R

riyaz.mansoor

Have compiled code. IE, variables not declared are declared in the
module level.

Form has an option group and a subform control. When an option is
clicked its "respective" (whose name is contained inthe clicked
options tag) form is loaded into the subform via the code below. That
bit works fine. The problem is that the form loaded into the subform
control are of different sizes, so I need to resize the main form and
subform control such that the form that is loaded into the subform
control is perfectly visible and nicely sized. I'm using the following
code. The height works fine, but somehow i'm not getting the width.
I've highlighted in the code where the problem is.

What should I be looking at

Note: the 2 / 8 * 1440 are placed to give some buffer


Dim aCtl As Access.Control
Set aCtl = Screen.ActiveControl

Dim aFrm As Access.Form
Set aFrm = aCtl.Parent.Form

' get form name to open
Dim frmNameToLoad As String
For Each tCtl In aCtl.Controls
If tCtl.ControlType <> acLabel Then
If aCtl.Value = tCtl.OptionValue Then
frmNameToLoad = Trim$(tCtl.Tag)
Exit For
End If
End If
Next tCtl

tInt = 0
' get subform control into which form will be loaded
Dim subFormCtl As Access.subForm
For Each tCtl In aFrm
If tCtl.ControlType = acSubform Then
tInt = tInt + 1
If tInt > 1 Then Err.Raise 1024, "NO more than one subform
allowed"
Set subFormCtl = tCtl
End If
Next tCtl

If tInt = 0 Then Err.Raise 1024, "ONE subform must be contained"

subFormCtl.Visible = False
subFormCtl.SourceObject = frmNameToLoad

If Len(frmNameToLoad) = 0 Then

aFrm.InsideHeight = aCtl.Top + aCtl.Height + 180
aFrm.InsideWidth = aCtl.Top + aCtl.Width + 180

Else

' this is GOOOOOD
subFormCtl.Height = subFormCtl.Form.InsideHeight + 2 / 8 * 1440
' this is BAAAAAD
subFormCtl.Width = subFormCtl.Form.InsideWidth + 2 / 8 * 1440

Dim sfMaxLeft As Integer, menuMaxLeft As Integer, maxLeft As
Integer
sfMaxLeft = subFormCtl.Left + subFormCtl.Width
menuMaxLeft = aCtl.Left + aCtl.Width
maxLeft = IIf(sfMaxLeft > menuMaxLeft, sfMaxLeft, menuMaxLeft) +
2 / 8 * 1440

Dim sfMaxTop As Integer, menuMaxTop As Integer, maxTop As Integer
sfMaxTop = subFormCtl.Top + subFormCtl.Height
menuMaxTop = aCtl.Top + aCtl.Height
maxTop = IIf(sfMaxTop > menuMaxTop, sfMaxTop, menuMaxTop) + 2 / 8
* 1440

aFrm.InsideHeight = maxTop
aFrm.InsideWidth = maxLeft

subFormCtl.Visible = True

End If
 

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