Share via

Position form bottom left using window size

Anonymous
2013-04-09T11:29:39+00:00

Hello, I want to position my form in the bottom left of the windows screen not access window bottom and I know I can use (DoCmd.MoveSize ,Right, Down, Width, Height) but I need to find the screen size then put the form in the bottom left in case the screen size changes. Where can I find this VBA? I'm finding bits and pieces of info everywhere but not really a solid code I can just use with no altering. Thanks!

I did try below but whats missing? I get debug on .Width and .Height?

'Positions form to bottom left

  Me.Left = Screen.Width - Me.ScaleWidth

  Me.Top = Screen.Height - Me.ScaleHeight

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2013-04-09T12:23:44+00:00

Copy the following code into a standard module, at the top (i.e. above all Subs and Functions, if any):

' -------------

Public Declare Function GetSystemMetrics32 Lib "User32" _

    Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, _

    ByVal hdc As Long) As Long

Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, _

    ByVal nIndex As Long) As Long

Private Const HWND_DESKTOP As Long = 0

Private Const LOGPIXELSX As Long = 88

Private Const LOGPIXELSY As Long = 90

Function TwipsPerPixelX() As Single

    Dim lngDC As Long

    lngDC = GetDC(HWND_DESKTOP)

    TwipsPerPixelX = 1440& / GetDeviceCaps(lngDC, LOGPIXELSX)

    ReleaseDC HWND_DESKTOP, lngDC

End Function

Function TwipsPerPixelY() As Single

    Dim lngDC As Long

    lngDC = GetDC(HWND_DESKTOP)

    TwipsPerPixelY = 1440& / GetDeviceCaps(lngDC, LOGPIXELSY)

    ReleaseDC HWND_DESKTOP, lngDC

End Function

' -------------

You can only position a form at an arbitrary position on the screen if its Popup property is Yes.

You can then use the following to move the form to the lower left corner:

    Dim h As Long

    h = GetSystemMetrics32(1) * TwipsPerPixelY ' screen height in twips

    DoCmd.MoveSize 0, h - Me.WindowHeight

The form will probably be partly hidden behind the taskbar...

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2013-04-09T13:38:18+00:00

    Hans, Thank you....

    Was this answer helpful?

    0 comments No comments