Open popup form on correct position (1 Viewer)

gstylianou

Registered User
Good evening,
I have one form which includes a button to the bottom corner (left). I would like to find a way so that if I press this button I can open a popup form just above this button.

It is important, however, that since If i have a different screen display on my computer, automatically the code to read the position of the button and the form to be open to the right place. Is there any way so to do that?
(I attach a base example)

thanks in advanced
 

Attachments

isladogs

High Noon Moderator
It can be done by detecting the overall screen size, the screen position of the button and the popup form size but I think it will require some fairly complex code.

I have a different suggestion which will be far easier.
Change your popup form so that it becomes a hidden subform.
Place it where you want it on the main form.

Now change your button code so this makes the new subform visible.
You could also do this so clicking the button again hides the subform.
 

gstylianou

Registered User
Hi and thanks for your info,

Therefore, its not a solution for me to hide the form because i cannot put it into a main form because there are many controls and this is problem...

But, please help me on how can find the screen position of the button if you want... I mean is there a way to read automatically this position and store it in a field?
 

isladogs

High Noon Moderator
Hi and thanks for your info,

Therefore, its not a solution for me to hide the form because i cannot put it into a main form because there are many controls and this is problem...

But, please help me on how can find the screen position of the button if you want... I mean is there a way to read automatically this position and store it in a field?
It doesn't matter that you have lots of controls on the form.
The subform can be placed over the top or underneath other controls as its normally invisible. Whilst it will then cover those other controls when visible, so would a popup form.

As I said before, the code to do what you want is complicated.
You can't store the info in a table as it will change with screen size and resolution.
If you really want to do it, do a site search or Google search
Here's a link that may help though I'm sure you'll find others
https://bytes.com/topic/access/answers/858357-absolute-position-control
 

isladogs

High Noon Moderator
Arnel's solution perfectly illustrates what I was trying to say:

The position is hard coded into the form code
So whilst it works perfectly at certain resolutions it gives less than ideal layouts at other resolutions / screen sizes

For example:
a) Perfect at 1680x1050 or 1400x1050 (shown below)



b) Wrongly placed at 800x600 or 1280x720 (shown below)



If differing resolutions aren't an issue then by all means go for it.
 

Attachments

Last edited:

isladogs

High Noon Moderator
Hi Arnel

somewhat manageable now
Not really - I've just tried it at 3 random resolutions with & without the form maximised. In several cases, the popup form covers the button itself.

Two more examples attached e.g.



This isn't intended as a criticism of your code:
Hard coding position values will work on the monitor used when coding and if the form state (restore / maximise) isn't changed.

However as soon as you change the resolution, monitor size or form state, the results are unpredictable,
To solve this, you need to take account of all of these things...

Personally I'd rather do it a different way but that's just me
Attached is a simplified version of what I would do instead using a subform
 

Attachments

arnelgp

error reading drive A:
did you reboot after changing resolution?
i think the op will be using only one resolution.
and other users wll not be be switching resolution just to make it fail.
 

isladogs

High Noon Moderator
Hi arnel

No I didn't reboot - I closed the app, changed the resolution then reopened it.

I'm not criticising your code nor am I trying to make it fail.
My response was based on experience of doing the same thing.

The apps I distribute are used by a large number of users with different screen sizes, shapes & resolutions. I have to make them 'fit' all scenarios.

I use a custom made form resizer that works in almost all cases.
Many of my example databases include that.
It almost always works well
However that too occasionally has issues e.g. option boxes can get over enlarged and tabbed pages can be problematic.

As I wrote in a previous reply:
If differing resolutions aren't an issue then by all means go for it.
 

isladogs

High Noon Moderator
Hi gstylianou

In case you're still looking for a solution that will scale up / down in different resolutions, I just found the attached utility on Stephen Lebans' website: http://lebans.com/openform.htm



For future reference, although many years old, his site is still very useful for anything graphics based

NOTE: It was an old A97 file but I've converted it to ACCDB here.
There was the usual conversion error about user level security no longer being implemented but you can ignore that.

Like most things on his site, the code has lots of complex API calls but the code needed to use the effect on a form is just one line e.g.

Code:
blRet = PositionFormRelativeToControl("Form2", Me.Command0, 0)
I've done the same tests as I did on arnel's solution and it worked every time

I'm going to use it myself to place a popup control zoom form just above the control being 'zoomed'
 

Attachments

arnelgp

error reading drive A:
it doesn't work on x64 access, it's popping on same location. already i converted it to x64 with no errors.
 

isladogs

High Noon Moderator
Hi arnel

Thanks I was going to try that later ....

Just tried using it for this purpose as I mentioned earlier
I'm going to use it myself to place a popup control zoom form just above the control being 'zoomed'
It didn't work.
Perhaps its because the control being clicked is in a subform ...?
Maybe I could get it to do so with a bit more work but I've left it for now as its not that important to me...

For that purpose, I also can't use your solution as the control position varies.
Nor can I use mine due to the nature of the subform

You win some, you lose some ... ;)

Anyway, the OP now has 3 solutions to choose from so at least one should be OK for his/her needs
 

gstylianou

Registered User
Dear friends, thanks a lot for your help....was really useful all details..!!

Moreover, my friend Ridders, the link you send me about to download an example is not working because i'm using Access 2016 32Bit.... Any idea?

Thanks again all of you
 

isladogs

High Noon Moderator
Hi

I'm also working in A2010 32-bit so I'm not sure which link you're referring to.

If you are referring to the link on Stephen Lebans' website, I also attached an accdb version of the same file in that post so you don't need to do it yourself.
 

gstylianou

Registered User
Hi

I'm also working in A2010 32-bit so I'm not sure which link you're referring to.

If you are referring to the link on Stephen Lebans' website, I also attached an accdb version of the same file in that post so you don't need to do it yourself.
Where is the accdb file my friend?
 

gstylianou

Registered User
Good morning to all,

Does anyone know what I can do about the attached message given by access by opening a form?

Where can I find this file and how do I install it in my Office 2016 package (32bit)

Thanks

(i'm using a module in order to auto find the screen resolution)
 

Attachments

The_Doc_Man

Happy Retired Curmudgeon
When you display this pop-up, what are you doing with it? Does it have multiple special controls or data? Or is it simply a message that you read and then click to make it vanish? Even if the message is dynamic, my comments would apply if there is nothing else about the message that requires interaction. The key is "click to close the message" as the ONLY thing you would do. If there is more to the pop-up, then don't bother reading any more.

If the situation IS just a "click to close" and nothing else, consider creating an overlapping text box or label (both of which support click events) and make it so it hides the controls "beneath it" when visible - but then in the .FormLoad event, you make it not visible. You have PLENTY of dynamic control over the control's (Top, Left,Height,Width) properties so moving it somewhere relative to the button would be trivial.

What I did for the "make the message go away" step was in the control's OnClick routine I did a .SetFocus back to the triggering control and let that event fire (which it does anyway, I later discovered), and then when the OnClick regains control, make the text box/label become .Visible=False. You have to do it that way because you can't make a control invisible if it still has focus, so .LostFocus doesn't help. (You still have the focus and are about to lose it, but not quite yet...)

Also, are your computations in twips or something else? If you keep the computations in twips, all of the screen-size issues (or at least most of them) should cancel out. The only major "gotcha" comes from the fact that there is no generally convenient way to know the physical dimensions required for a text string on a display. You can do this computation on a report, but not on a form.
 

isladogs

High Noon Moderator
Good morning to all,

Does anyone know what I can do about the attached message given by access by opening a form?

Where can I find this file and how do I install it in my Office 2016 package (32bit)

Thanks

(i'm using a module in order to auto find the screen resolution)
You haven't said the context but I'm guessing this is related to the database I provided in post 11 which was originally on Stephen Lebans website.

This includes a module modPositionWindow with loads of api calls including:

Code:
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
That module MUST be included in any app using the same code

In case you've omitted it, I'm attached this as a text (bas) file so you can import it easily into the VBE

BTW - did you consider my subform alternative which I uploaded in post #8. I ask as its similar to what Doc has just suggested
 

Attachments

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top