How to find the "Correct" position of a form

mloucel

Member
Local time
Today, 02:11
Joined
Aug 5, 2020
Messages
356
Hello ALL, me again..

Thru trials and errors and a bit of Help from Richard Rost, I have been able to ALMOST place the forms to a specific location I need them to appear, nothing major but it does help a lot for different monitors without complicated coding, here is my dilemma:

in order to find the current position, I use a little button in each form, which is never left for the EU, just for me to test, then I use the following code:
Code:
Private Sub FindTwips_Click()
    With Forms(0)

     MsgBox "This form is " & .WindowLeft _
     & " twips from the left edge of the Access window and " _
     & .WindowTop _
     & " twips from the top edge of the Access window."

    End With
End Sub

Problem I have found is that the numbers given are absolutely FALSE, at least gave me an idea of where is more or less located the form, then I adjust.
EX:
I move the form to the position I need it and press the FT button
I got 6285
and 1755{Top]
change the code adjusting to those numbers but is way off from where I need the form, so I manually adjust the twips until I get it right which happens to be:
10000 {Left] and 5000 [Top}

funny part is that when I click the FT button, I got 6289 and 1755,

if I change to those numbers then it goes to a position I do not want, then use my adjusted numbers and it works ...

So why Access is giving me those numbers and not the position I want 10000 [L] and 5000 [T]

I am not sure if I made myself clear
Thanks for any Help is not a life and death situation JUST SIMPLY CURIOSITY, but if you guys know a better way it will be appreciated.

Maurice.​
 
What is the code you are using to position the form? I just tried to use your code and a simple form that allows for direct entry of the twips values and it works pretty good. It won't be exact using the FindTwips, but it should be very close.

Edit: I played around with this a bit and the form moved in increments of 15 twips on my screen. So if I use code to set your position of 10000 and 5000 the actual values for me read 10005 and 4995 using your above code. If I then added 7 twips to the Left value, that was not enough to move the form at all, but 8 twips caused it to move to the next higher value of 10020 on the screen.

I'm using another button on the form that reads two numbers from a couple of controls on the form itself.
Code:
Private Sub MoveForm_Click()
   Me.Form.Move Me.LeftVal, Me.TopVal
End Sub
 
Last edited:
What is the code you are using to position the form? I just tried to use your code and a simple form that allows for direct entry of the twips values and it works pretty good. It won't be exact using the FindTwips, but it should be very close.

Edit: I played around with this a bit and the form moved in increments of 15 twips on my screen. So if I use code to set your position of 10000 and 5000 the actual values for me read 10005 and 4995 using your above code. If I then added 7 twips to the Left value, that was not enough to move the form at all, but 8 twips caused it to move to the next higher value of 10020 on the screen.

I'm using another button on the form that reads two numbers from a couple of controls on the form itself.
Code:
Private Sub MoveForm_Click()
   Me.Form.Move Me.LeftVal, Me.TopVal
End Sub
I just move freely the form to different positions until I found the right place, then hit my button that gives me the results on that pos.
but I will try your suggestion, and thanks for the tip.
Also it is curious but if I open a form, then with a button open another form the numbers go wild, and that confuse me more than ever.
 
I just tested your scenario from another form and for me the FindTwips code is showing 0 Left and 0 Top values. So obviously incorrect, but it looks like it is in the correct position. This is because the FindTwips code is referencing the collection and not the actual form by name. If you want it to work correctly, you will need to close the calling form first and then open the form in question.

If the form is still not opening in the correct place, you will need to execute the Me.Form.Move command in the OnOpen event of the form. The only reason I used controls on the form for manipulating the values was for testing puposes. You don't have to do that.
 
Last edited:
I have an article and example app discussing how to accurately position forms and controls on the screen:

The code provided should work for any monitor size & resolution without any issues.
Do bear in mind that the position for popup forms is relative to the screen, whereas for standard forms it is relative to the application window
 
Last edited:
I just tested your scenario from another form and for me the FindTwips code is showing 0 Left and 0 Top values. So obviously incorrect, but it looks like it is in the correct position. This is because the FindTwips code is referencing the collection and not the actual form by name. If you want it to work correctly, you will need to close the calling form first and then open the form in question.
Great, thanks, but sometimes I need that form opened, thou I found out (at least for 7 of our different monitor sizes that leaving the Top at 1500 seems to place at least any form right at the middle, just will figure out the other value (L) and have a more or less common for all of them and should work.

Thanks a lot for helping me, I have no idea what in the world are twips but seems like I've been finding my way around,

Like someone said around here:

"The devil is in the details"

Maurice.
 
I have an article and example app discussing how to accurately position forms and controls on the screen:

The code provided should work for any monitor size & resolution without any issues.
Do bear in mind that the potion for popup forms is relative to the screen, whereas for standard forms it is relative to the application window
Thank you Obi Wan, your code is simply flawless, and I am learning a lot.

Maurice.
 
I struggled with this issue a lot in the past so isladogs article was a life saver.
 
I have no idea what in the world are twips

It's a unit of measure for a display where you don't know a priori what resolution has been selected for that display. So by working in twips, you let Access draw on the screen independent of pixel size.

One twip = 1/1440 of an inch and it doesn't "care" whether your screen is set for 1024 x 768 resolution or 1920 x 1080 or something else. It is also 1/20th of a Point in printing font-size terms.
 

Users who are viewing this thread

Back
Top Bottom