Form automatically goes to the right side or left (1 Viewer)

hfsitumo2001

Member
Local time
Yesterday, 18:17
Joined
Jan 17, 2021
Messages
365
Hello, what is in the property of the form that can place the form to the right side of the screen when we open it.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:17
Joined
Feb 28, 2001
Messages
27,172
There are THREE things to consider in your problem. First, there is the physical display size. Then there is the window size of Access itself. Finally, there is the size of the form to be displayed.

Here is a discussion of the subject.


Note that you have to place things left-oriented & top-oriented, because the form's coordinate system is set up with 0 on the left edge and 0 at the top edge. The way to right-justify is to get the physical screen width and then set the left edge of your form equal to the screen width minus the form width.

I kind of cheated, because I always maximized my dispatcher form so I could get its measurements form the form's properties. All of the forms I opened were children of the dispatcher so were bound relative to it. However, it sounds like you want to leave some things visible on your screen that are NOT part of Access. In that case, I think you have to use WinAPI routines to get window measurements and there is a WMI routine that will give you physical screen measurements.

Here is a WMI link that might help.


Remember, the monitor / screen size is the OUTERMOST object you are measuring. You still have to be aware of the window size of Access itself, which will include task bar and possibly a scroll bar, and then you have the form with which you are struggling.
 

isladogs

MVP / VIP
Local time
Today, 02:17
Joined
Jan 14, 2017
Messages
18,216
As a simple example, to place your form at the top left corner, use this code in Form_Load
Code:
DoCmd.MoveSize 0,0

Moving to the right will require knowledge of the monitor size as already stated
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:17
Joined
May 7, 2009
Messages
19,231
something you can use.
 

Attachments

  • RePositionForm.accdb
    612 KB · Views: 158

MarkK

bit cruncher
Local time
Yesterday, 18:17
Joined
Mar 17, 2004
Messages
8,181
Here's another way without using API calls...
 

Attachments

  • RePositionForm.accdb
    516 KB · Views: 156

isladogs

MVP / VIP
Local time
Today, 02:17
Joined
Jan 14, 2017
Messages
18,216
Here's another way without using API calls...
That's very neat! Whilst using APIs works well, this class based approach needs far less code.

For anyone interested who tries it, the form reverts to the centre position after 0.75 seconds.
To make the position 'stick', change the timer interval in cmdClick event on the form from 750 to 0.
Also make the 'Centre' button cmd11 both visible and enabled to move the form back to the screen centre again.
 

MarkK

bit cruncher
Local time
Yesterday, 18:17
Joined
Mar 17, 2004
Messages
8,181
Thanks. Here's a version with the changes Colin suggested.
 

Attachments

  • RePositionForm.accdb
    512 KB · Views: 153

hfsitumo2001

Member
Local time
Yesterday, 18:17
Joined
Jan 17, 2021
Messages
365
something you can use.
Thank you Arnel, I will try to use it not on click but on load of the form, because I use the Access Switchboard menu, which is when we click it it loads the form. Can I do it like that?. And I should import module1 right?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:17
Joined
May 7, 2009
Messages
19,231
you can use it on the Form's Load/Open event or even on the Click event when you Open that form.
yes you import both Modules.
 

hfsitumo2001

Member
Local time
Yesterday, 18:17
Joined
Jan 17, 2021
Messages
365
you can use it on the Form's Load/Open event or even on the Click event when you Open that form.
yes you import both Modules.
Arnel, how can I understand that the both standard modules are being called in the form, when I tried to see the on click, it did not mention the name of the module.

Thank you
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:17
Joined
May 7, 2009
Messages
19,231
Both modules are being used.
 

Atthe

Member
Local time
Today, 02:17
Joined
Oct 26, 2021
Messages
57
something you can use.

Hi Arnel,

I have implemented your sample into my database and this works great on single monitors however I am experiencing difficulties with users who have dual monitor setups ( Laptop and separate display) Some of the forms overhang onto the other display etc,

Have you any ideas or is this setup not suitable for dual monitors?

Many Thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:17
Joined
May 7, 2009
Messages
19,231
sorry, have not tested on multi-mon, coz i haven't have one.
 

Users who are viewing this thread

Top Bottom