Move and Maximize Sub forms

Hi All,

Is there a way to Maximize and move sub forms in the main form thru code in ms access 2010?
Please let me know if possible
Who is Participating?
Dale FyeCommented:
Start out by creating a button, name it cmd_Resize, and place it just above the subform.  Note the Top property of this button and of the subform.  Make the caption on the button something like "Increase".  Then the code behind that button would be something like the code below (this is untested, but should work properly).
Private cmd_Resize_Click

    Dim sngOrigButtonTop  as single
    Dim sngOrigSubFormTop as single
    Dim sngOrigSubformHeight as single

    'Replace the 3.5, 3.8, and 3.0 in the next three lines with the original values for the controls on the form, before you make changes
    sngOrigButtonTop = 3.5 * 1440
    sngOrigSubformTop = 3.8 * 1440
    sngOrigSubformHeight = 3.0 *1440

    on error goto ProcError

    docmd.Echo Off
    if me.cmd_Resize.Caption = "Increase" then
          'Replace the 1.0 and 1.3 in the following code with the positions where you want the top of the button
          'and the top of the subform when they are expanded.
          me.cmd_Resize.Caption = "Decrease"
          me.cmd_Resize.Top = 1 * 1440      '(1" = 1440 twips)
          me.subformControlName.Top = 1.3 * 1440
          me.subformControlName.Height = sngOrigSubformTop - (1.3 * 1440) + sngOrigSubformHeight
          me.cmd_Resize.Caption = "Increase"
          me.subformControlName.Height = sngOrigSubformHeight
          me.subformControlname.Top = sngOrigSubformTop
          me.cmd_Resize.Top = sngButtonTop
    End If

    docmd.Echo true
    Exit Sub

    debug.print "cmd_Resize_Click", err.number, err.description
    msgbox err.number & err.description, , "cmd_Resize_Click
    Resume ProcExit

End Sub

Open in new window

Dale FyeCommented:
Are you talking about changing the size of the subform, when the main form changes sizes?
John TsioumprisSoftware & Systems EngineerCommented:
I guess we need a screenshot of your current layout to "see" what you want to achieve and why...
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

frimyAuthor Commented:
Hi All
thanks for responding
see attach.
i want to be able to see more records in the sub form, so i want to be able to move the sub form up and then make it bigger in the bottom,
and then put back like it was before.
Dale FyeCommented:
you might consider using a tab control, and moving some of the other data to a tab.

but one method to do this would simply be to add a button, maybe in the top right corner above the subform, and when clicked, you would move that button upwards to some location, then move the top of the subform just below that button and then increase the height of the subform.  

Then, when the user clicks that same button again, you would decrease the height of the subform to it's original height and set the Top property back to its original value and move the button back to its original location.

This would work sort of like how the you can hide and reveal the navigation pane.
frimyAuthor Commented:
<<  you would move that button upwards to some location  >>
can you explain how to move a button and then the subform in code.
frimyAuthor Commented:
Hi Dale,
yes i tried it ,
it works very good.
i also start using now the Left property.
Thanks and have nice day
Dale FyeCommented:
glad I could help
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.