Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280

    Me.Move not positioning a form correctly

    I have a popup form which I move on opening using the Me.Move (left, top) command.
    I set the left value to the Me.TextBox.Width on the calling form. It used to work with the popup appearing exactly positioned to the right of the TextBox.

    After making a few minor changes, including increasing the size of TextBox, the popup is now appearing about 1/10th inch to the right.
    Can't see why this is happening. According to the documentation, Left is The screen position in twips for the left edge of the object relative to the left edge of the Microsoft Access window.
    Measuring it with a ruler, it is certainly 1/10th further to the right.

    As a workaround, I am specifying Left exactly rather than getting the value from Me.TextBox.Width.



    I would like to understand what is going on though.

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Perhaps your calling form is now opening in a different place? As you say, Move is relative to the app window and not where some other form textbox is located.
    If that is the case, you need to know the leftmost position of the 1st form + the left property of the textbox + the width of the textbox?
    Also, perhaps you changed the Auto Center or Auto Resize properties of the 1st form at some point? Or have I misunderstood and you're not trying to open 2nd form relative to the 1st?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Micron,

    Thanks for your reply. I don't think I changed any auto centre or auto resize properties, but I will check all these. The first form is always loaded Maximized when the application loads.
    Just as a simple experiment, I changed the Me.Move to be Me.Move 0,0.
    As can be seen in the image below, it opens at the top of the access window, but about 1/10th inch to the right.

    Click image for larger version. 

Name:	Capture.JPG 
Views:	16 
Size:	11.3 KB 
ID:	47481

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    It looks like the calling form Bird Log is not a popup so the positions on that are relative to the database window within the application interface.
    By contrast the position of popup forms is independent of the application interface which may explain your experience.

    Try making both forms the same as each other - either popup or not

    Also have a look at the various forms in my example app Accurately Move Forms & Controls. You may find something of use for your purposes
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    If after checking you want to create a test db with the 2 forms, re-test for the problem in the test db, and if it's still there, zip and post it here and I or someone will take a look. You could remove everything that's not needed to replicate the issue. The only other thing I can think of a the moment is that form2 isn't the active window when the code runs, and MoveSize works on the active form (but not on a maximized form). Rather than allow Access to determine which form to apply a method to, it might be better to explicitly pass the form name, or use a different event - such as Activate (however, that will likely fire every time you activate the form window). This might help

    https://support.microsoft.com/en-us/...86553682f9#bm3
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Hmm, I bow to the experience Isladogs regarding these things, but
    By contrast the position of popup forms is independent of the application interface which may explain your experience.
    what then are their positions relative to if not the app window? Surely it is not be the last form opened?
    EDIT - even if it was, it doesn't work as expected when OP set the values to 0.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    For popup forms, it is relative to the screen.
    Try this. Have 2 identical forms, one popup & the other not, and use DoCmd.MoveSize 0,0 in the Form_Load event of each. Note the difference.

    Change the 0,0 on the popup form to be relative to the first form position & size. Again you will get a discrepancy for the same reason.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  8. #8
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I got this far and see the difference
    Try this. Have 2 identical forms, one popup & the other not, and use DoCmd.MoveSize 0,0 in the Form_Load event of each. Note the difference.
    However, OP stated
    I have a popup form which I move on opening using the Me.Move (left, top) command.
    and followed that with a pic showing the 2nd form opening just left of the 1st form, not the app window. That's the confusing part - it' supposedly a popup set to move to 0,0 yet it's just right of the 1st form.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Actually there's a difference in behaviour between DoCmd.MoveSize & Me.Move.
    The outcomes also depend on the type of border used.

    Using A365, a popup form set as DoCmd.MoveSize 0,0 in fact opens shifted approx 1/10 inch (144 twips) from the left margin of the screen
    To get it to open precisely at the top left try something like DoCmd.MoveSize -144, 0 (for a sizable, thin or dialog border style)

    However using Me.Move causes the popup form to be constrained to the application window rather than the whole screen
    Using Me.Move 0,0 will cause it to open exactly in the top left of the app window if the border style is set to none
    However it opens shifted approx 0.1 inch to the right for a sizable, thin or dialog form
    Me.Move -144,0 seems to be about right to get to manage the unwanted horizontal shift for a sizable, thin or dialog form

    Add appropriate values for the width / height of the first form to get it to appear in the desired position

    My example app referenced earlier illustrates many of the different possible outcomes
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  10. #10
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Thanks for your replies. In fact, Isladogs seems to have cracked it.
    When I changed the popup to have no border, it did indeed start at the left of the window when using Me.Move 0, 0 (although for some reason, the database got stuck and had to cancel with Task Manager).

    Looking at my numbers, I was setting the left position manually to about 144 less than the TWIPS value of the width of the item, so 144 seems right for the form border and I can now use the 144 rather than setting a hard coded value.

    Thanks for all your help.

  11. #11
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Having got this far, I may as well provide a few more details.

    There are actually 3 different form width measurements - all measured in TWIPS:
    1. WindowWidth = total width of the window containing a form - including borders.
    2. InsideWidth = inside width of a form including the scroll bars and the record selectors
    3. Width = interior dimensions of a form, excluding the scroll bars and the record selectors.
    See e.g. https://docs.microsoft.com/en-us/off...rm.insidewidth

    To illustrate the differences I created a simple form 10cm wide (5670 twips) with no record selectors & no scrollbars

    I then added this code to the Form_Load event:

    Code:
    Private Sub Form_Load()
    
      Dim bytBorderStyle As Byte
      Dim strText As String
    
      bytBorderStyle = Me.BorderStyle
    
      strText = vbCrLf & "Border Style = " & Switch(bytBorderStyle = 0, "None", bytBorderStyle = 1, "Thin", bytBorderStyle = 2, "Sizable", bytBorderStyle = 3, "Dialog")
      strText = strText & vbCrLf & "========================="
      strText = strText & vbCrLf & "Form Window Width = " & Me.WindowWidth
      strText = strText & vbCrLf & "Inside Width = " & Me.InsideWidth
      strText = strText & vbCrLf & "Form Width = " & Me.Width
      strText = strText & vbCrLf & vbCrLf & "Left/Right Border Width = " & (Me.WindowWidth - Me.InsideWidth) / 2
      strText = strText & vbCrLf & "Record Select0r Width = " & Me.InsideWidth - Me.Width
         
     Debug.Print strText
    
    End Sub
    I then toggled through the 4 border styles and got these results in the immediate window

    Code:
    Border Style = None
    =========================
    Form Window Width = 5670
    InsideWidth = 5670
    Width = 5670
    Left/Right Border Width = 0
    Record Selector Width = 0
    
    
    Border Style = Thin
    =========================
    Form Window Width = 5910
    InsideWidth = 5670
    Width = 5670
    Left/Right Border Width = 120
    Record Selector Width = 0
    
    
    Border Style = Sizable
    =========================
    Form Window Width = 5970
    InsideWidth = 5670
    Width = 5670
    Left/Right Border Width = 150
    Record Selector Width = 0
    
    
    Border Style = Dialog
    =========================
    Form Window Width = 5910
    InsideWidth = 5670
    Width = 5670
    Left/Right Border Width = 120
    Record Selector Width = 0
    All those with thin red line borders look identical but the actual widths vary slightly
    So the actual figure you need to allow for is NOT 144 - use 120 (thin / dialog) or 150 (sizable) when running Access 16.0 (2016/2019/2021/365)
    In earlier versions such as 2010, the border styles look different & the border thickness values may differ

    Now repeat with record selectors.
    An additional 285 twips is added to the inside width & window width properties but the width property is unchanged (see above)
    In other words, the InsideWidth is 285 twips more than the Width e.g.

    Code:
    Border Style = Sizable
    =========================
    Form Window Width = 6255
    Inside Width = 5955
    Form Width = 5670
    Left/Right Border Width = 150
    Record Selector Width = 285
    Finally repeat with a vertical scrollbar and an additional 255 twips is added to the inside width & window width properties
    i.e. Scrollbar Width = 255

    All of this means that if you need EXACT placement of one form relative to another, you need to allow for each of the properties involved

    The screenshot below is from the example app in my article Accurately Move Forms & Controls (isladogs.co.uk) and was done in Access 2010

    Click image for larger version. 

Name:	FormInfo.png 
Views:	15 
Size:	100.6 KB 
ID:	47484
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  12. #12
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Thanks very much - very useful.
    Actually, running experiments myself I managed to confirm that the left adjustment that needs to be made is indeed 150 TWIPS for sizeable and 120 TWIPS for Thin or Dialog.
    I think there is also a vertical adjustment that needs to be made for all but None of 15 TWIPS or 1 pixel - not able to confirm that from code, just by looking. May be wrong on this though.

  13. #13
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Excellent. The figures have to be multiples of 15 so the values correspond to whole pixels.
    I hadn't realised you needed to know about vertical position as well.

    You're going to need to either ensure both forms have the same border style or compensate for the differences in border thicknesses

    Say for example you want to open Form8 directly below form 7C with both aligned on the left:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	14 
Size:	13.2 KB 
ID:	47485

    If both are popup with sizable borders then this works:

    Code:
    Private Sub Command1_Click()   
        DoCmd.OpenForm "Form8"
        Forms!Form8.Move Me.WindowLeft, Me.WindowTop + Me.WindowHeight - 150
    End Sub
    However if form 7C is sizable and form 8 has thin border, the form move code needs to be:
    Code:
    Forms!Form8.Move Me.WindowLeft + (150 - 120), Me.WindowTop + Me.WindowHeight - 120
    Hopefully obvious why those particular values are needed
    ..... etc, etc for all other possible form border style combinations and if one form is popup but not the other ....

    It may be easier to manage if you put the move code in the second form and reference the first form's position/size

    Have fun!
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  14. #14
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Are you sure you are correct on the vertical adjustment. From my experiments the vertical only needed to be adjusted by -15 TWIPS if not None border.
    I think your Form 8 might be slightly overlapping the bottom of Form 7.
    Perhaps you could try it again with -15 instead of 150 or 120.

  15. #15
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    I'm absolutely certain that the vertical adjustment is NOT 15.
    I started by testing that - there was a clear vertical gap between the forms.

    However I should have specified that the top form was popup

    Attached is a simple example with 4 pairs of forms, each with sizable border:
    1. A & B - neither are popup
    2. C & D - C not popup, D is popup
    3. P & Q - P is popup but Q isn't
    4. X & Y - both are popups

    Click image for larger version. 

Name:	Capture.PNG 
Views:	13 
Size:	67.7 KB 
ID:	47486

    The boundaries of a popup form are quite difficult to determine precisely.
    Click on the popup form to see the edge line.

    These are the different adjustments that I believe are required required for these pairs of forms:
    1. A & B - NO adjustment required for form B

    Code:
     intTop = Forms!FormA.WindowTop + Forms!FormA.WindowHeight        intLeft = Forms!FormA.WindowLeft
            
            Me.Move intLeft, intTop
    2. C & D - horizontal adjustment of -150 for form D
    Code:
     intTop = Forms!FormC.WindowTop + Forms!FormC.WindowHeight
            intLeft = Forms!FormC.WindowLeft - 150
            
            Me.Move intLeft, intTop
    3 P & Q - adjustment of 150 in both directions for form Q
    Code:
    intTop = Forms!FormP.WindowTop + Forms!FormP.WindowHeight - 150
            intLeft = Forms!FormP.WindowLeft + 150
            
            DoCmd.MoveSize intLeft, intTop
    4. X & Y - adjustment of 150 in both directions for form Q - EXACTLY the same as P & Q

    Code:
      intTop = Forms!FormX.WindowTop + Forms!FormX.WindowHeight - 150
            intLeft = Forms!FormX.WindowLeft + 150
            
            DoCmd.MoveSize intLeft, intTop
    Attached Files Attached Files
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 03-09-2017, 07:40 AM
  2. Passing form Left and Top positioning coordinates
    By GraeagleBill in forum Programming
    Replies: 7
    Last Post: 11-18-2013, 08:12 AM
  3. Replies: 15
    Last Post: 12-10-2012, 06:37 PM
  4. Help Needed Form Positioning
    By codybecker in forum Forms
    Replies: 3
    Last Post: 09-15-2010, 08:50 PM
  5. form positioning
    By taylorosso in forum Forms
    Replies: 5
    Last Post: 08-23-2009, 08:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums