Position popup relative to a command button.

Posted on 2006-03-21
Last Modified: 2008-02-01
I want to position a popup to the right of a subform.

I presume to use movesize, but that requires coordinates relative to the screen.

I activate the popup from a command button on the subform.

How do I get the top and left coordinates of the subform relative to the screen so I can use movesize?
Question by:ramrom
    LVL 16

    Accepted Solution

    First you will need the Top and Left coordinates of the Parent form.  This requires the use of API calles but fortunately Microsoft supplies all the code needed to leverage these API calls in the following KB article.;en-us;210141

    Using the GetFormDimensions() Function detailed the in the above KB article above, you would then get the Top and Left position of the Sub form and add those values to the Top and Left Form position acquired from GetFormDimensions().

    At this point you'll be armed with the location where you want the popup form to open up to but you'll need to pass that information to the form.  Typically this is done via the OpenArgs parameter.  You'll need a string parsing utility to extract the X and Y coordinates passed via the OpenArgs String.  If you don't have one the Access Developers Handbook (Published by SyBex) supplies a very good one expressly for this purpose.

    When the Form Loads you would parse the OpenArgs string for the X and Y coordinates passed in the step above and then use the DoCmd.MoveSize method to reposition the form.

    Although this process may seem very daunting at first once you're comfortable with the technique it's not so bad.  

    LVL 17

    Author Comment

    "Although this process may seem very daunting" ... actually it does not.I've been doing stuff like this for years. I just needed the pointer to the right API, and the sample code worked just fine.

    Rather than messing with openargs and string parsing, I gave my form a move subroutine which takes the coordinates, sets focus to self and does the movesize.
    I then docmd.openform and follow that with a call to the move sub.
    LVL 17

    Author Comment

    Oh Oh I just discovered that the above works fine if I feed GetFormDimensions() the main form, but I'm dealing with positioning the popup relative to a subform (actually a subform on a subform). I have not found a way to pass the subform to GetFormDimensions(). So I am back to square 1.
    LVL 17

    Author Comment

    Well ignore that. I found the right way to refer to the subform. It works.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now