How to Size to Fit Form for Popup Form

I have a popup form that floats over another form. What code can I execute to get the Size To Fit Form to apply to the popup form?
rmkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

thenelsonCommented:
>Size To Fit Form
Do you mean you want the border to automatically size to the form inside it?  Then set auto resize to yes.

If you want to size the popup to something else use:
Me.InsideWidth = <size in Twips>
Me.InsideHeight = <size in Twips>
Twips are 1440/inch
dannywarehamCommented:
If this is only opened over one form, do it through hardcoding the values (as thenelson has shown)
If it may be different sizes (if the main form is sizeable or changes) then you can capture the values and pass them.

In a module:

Public myLeft as long
Public mytop as long
Public myHieght as long
Public myWidth as long

Then in your main form (on the open pop up button)

myLeft = Me.Form.Left
myTop = Me.Form.Top
'etc

Then in the popup on load

Me.Form.Left = myLeft
Me.Form.Top = myTop
'etc

Idea...?
rmkAuthor Commented:
I guess I did not explain the question clearly enough. I always give my users the ability to re-size forms and I provide them with a menu item that invokes:

RunCommand acCmdSizeToFitForm

The problem is that the command applies to the active form and a popup form is never considered to be the active form.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

dannywarehamCommented:
Hey rmk

>>I always give my users the ability to re-size forms
Any particular reason why? Is this due to screen resolution differences between machines?
If your user resizes teh mina form, opening teh popup form with my example will automatically resize taht too.

>>a popup form is never considered to be the active form.
Not true.
If you can set focus to a control on teh popup (even if its the close command button), then it is the active form...

:-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rmkAuthor Commented:
Why - because my users demand it - they often keep multiple forms open and size and position them to see just what they want. Unless it's harmful, I try to expose as much Access and Windows functionality as possible.

You've certainly helped my take the blinders off. The menu item I was using for size to fit form was the native Access menu item under the native Windows menu. That particular item (as far as I can tell) never applies to a popup window. By adding a separate button to my custom toolbar, RunCommand acCmdSizeToFitForm does indeed work even on a popup form when it has the focus. Thanks

dannywarehamCommented:
No problem...
If you need anything else, give me a shout

:-)
thenelsonCommented:
While I was researching an answer, I see you came up with a solution.  Yours sounds simpler than mine.  I have the explaination and this might be useful to someone else for another problem.

>>a popup form is never considered to be the active form.
A popup form is never considered to be the active form IN ACCESS because a popup form is not in the Access container.  To see this, normalize Access and move the popup outside of Access or type:
?screen.ActiveForm.Name
in the immediate window and you won't get the popup form.

You can use RunCommand acCmdSizeToFitForm on the popup form if it has the focus which is different than being the active window.  This API call will set the Access focus to the window that has the focus and active RunCommand acCmdSizeToFitForm to it:

Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
Declare Function apiGetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long
Declare Function apiGetParent Lib "user32" Alias "GetParent" (ByVal hwnd As Long) As Long

Function SizeToFitForm()
    Dim hwnd As Long
    Dim hWndAccess As Long

    ' Get the handle to the currently active window.
    hwnd = apiGetActiveWindow()
    hWndAccess = hwnd

    ' Find the top window (which has no parent window).
    While hwnd <> 0
        hWndAccess = hwnd
        hwnd = apiGetParent(hwnd)
    Wend

    'put the focus on currently active window
    Putfocus hWndAccess
    'size it to fit
    RunCommand acCmdSizeToFitForm
End Function


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.