Open a popup formplaced over a control


Then I open a form with acdialog it always autocenter the opened form, but the autocenter property is false. The moveable property is Yes and I do a me.move of postion left and top of a control of the opening form. I use the onLoad event me.move with twips for contol of opening form, Me.window.Left + me.Control.left and +

What ever I change the number to of the move method it is still in the center. I would like to have it over the control since the popup form is associated to that control.

Thanks in advance.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Gustav BrockCIOCommented:
I cannot replicate that behaviour. The form sticks to the position where it is saved.

So try to recreate the form.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Me.window.Left + me.Control.left and +
Me refers to the active form. If you open a Dialog form, code runs only in that form, and no others. It would seem you'd need to refer to the "calling" form in order to position the popup dialog form correctly:

Me.Window.Left + Forms!CallingForm.Controls("NameOfTheControl").Left

Or perhaps I've misread something ...
BAndersConsultantAuthor Commented:
The The OpenForm call is the following

DoCmd.OpenForm frmName, acNormal, , , , acDialog, Me.WindowLeft + Me.LastUsedBox.Left & ";" & Me.WindowTop + Me.LastUsedBox.Top

In the frmName:

Private Sub Form_Load()

Dim XY

If Not IsNull(Me.OpenArgs) Then

    XY = Split(Me.OpenArgs, ";")
    Debug.Print "move", Me.OpenArgs
    Me.Move CInt(XY(0)), CInt(XY(1))
    Debug.Print "window", Me.WindowLeft, Me.WindowTop, Me.AutoCenter, Me.AutoResize, Me.FitToScreen
End If

End Sub

The debug.print gives the correct numbers and properties. Still, the form is placed a couple of inches to the right but as the same top of the LastUsedBox. It is more in the center.

Notice, AutoCenter, Autoresize and Fittoscreen are all False. PopUp is True.

Why Load Event, for unkown reason, the OpeArg is Null in the Open event.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

BAndersConsultantAuthor Commented:
I have done some more testing. If I turn of Pop-up it will place the form correctly. I have seen - somewhere - API being used for to move access forms. Do I need to use that?
Fabrice LambertConsultingCommented:
What about openning, positionning from the calling form, and turn the form to modal afterward ?
Something like:
Dim frm As Access.Form

DoCmd.OpenForm "Form1", acNormal
Set frm = Forms("Form1")
frm.Move 100, 100
frm.Modal = True
Set frm = Nothing

Open in new window

As for positionning, IIRC controls coordinate are relative to its parent form, so you'll need too add the calling form windowTop and windowLeft to the control's coordinate (plus a delta_X and / or delta_Y if needed).
BAndersConsultantAuthor Commented:
It works fine to move the form to the correct position.

But, since I need to open in acdialog mode to be able to to continue after that the closing of the form and a popup form (can only be set in Design view) to be able open other forms (the later, am I right?).
Fabrice LambertConsultingCommented:
hmm, maybe take advantage of events, or implement the observer design pattern.

In short:
- In the calling form, declare a form level variable with events representing your "dialog form".
- In the "dialog form", define the close event (even if empty).
- In the calling form, implement de close event of the "dialog form".
BAndersConsultantAuthor Commented:
The idea to use events also turned up here as well. But I have nerver done what you propose. Therefore,

- How do I declare a form level variable?
- The close event already exists and is quite empty.
- How do I implement the close event of the dialog form?

Please, i have tried but it is not accepted by the Access compiler. Just sketch, I have already Public variables for the return data.
Fabrice LambertConsultingCommented:
How do I declare a form level variable?
At top of your calling form:
Private WithEvents frm As Access.Form

Open in new window

How do I implement the close event of the dialog form?
In your calling form:
    '// Calling form's current event (use another one to fit your needs)
Private Sub Form_Current()
    DoCmd.OpenForm "Form1", acNormal    '// open the "dialog form"
    Set frm = Forms("Form1")            '// set reference so we can catch events
    frm.Move 100, 100
    frm.Modal = True
End Sub

    '// catch the "dialog form" close event
Private Sub frm_Close()
End Sub

Open in new window

In your "dialog form", define the close event empty
Private Sub Form_Close()
End Sub

Open in new window

You can only catch events from variables declared at form or class level, not in standard module.

This isn't my favorit solution as the control of variables's lifetime and scope is poor, but it is simplier to implement.

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
BAndersConsultantAuthor Commented:
You have opened a door for to use events. Many thanks
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.