Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

When I Open a form, I want to position it at a certain place on the screen.

Posted on 2004-04-29
10
Medium Priority
?
606 Views
Last Modified: 2012-05-04
When I Open a form during the execution of an application, how do I:

1. Using VBA, how do I place it in a certain position each time?
2. At the same time I would like to hide the form that called for it!
0
Comment
Question by:pmcontractor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 34

Expert Comment

by:flavo
ID: 10955195
Go in to design mode, put the form where you want it, press save (make sure auto centre is turned off in the properties) and bob's your uncle!

Good Luck!

Dave
0
 
LVL 34

Accepted Solution

by:
flavo earned 500 total points
ID: 10955204
>> 2. At the same time I would like to hide the form that called for it!

Me.Visible = False
Docmd.OpenForm "myOtherForm", acNormal
0
 
LVL 11

Expert Comment

by:Mighty_Silly
ID: 10955424
Greetings!

I normally add Docmd.Restore to the form's Form Open event also.

-Silly-
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Assisted Solution

by:moralju
moralju earned 500 total points
ID: 10955910

<Copy and paste this in a module>


'**********Code Start********
Option Compare Database
Option Explicit

Global Const WM_SM_CXVSCROLL = 2
Global Const WM_SM_CYCAPTION = 4
Global Const WM_SM_CXBORDER = 5
Global Const WM_SM_CYBORDER = 6
Global Const WM_SM_CXDLGFRAME = 7
Global Const WM_SM_CYDLGFRAME = 8
Global Const WM_SM_CYMENU = 15
Global Const WM_SM_CXFRAME = 32
Global Const WM_SM_CYFRAME = 33
 
Global Const WM_LOGPIXELSX = 88
Global Const WM_LOGPIXELSY = 90
 
Global Const WM_SWP_DRAWFRAME = &H20
Global Const WM_SWP_HIDEWINDOW = &H80
Global Const WM_SWP_NOACTIVATE = &H10
Global Const WM_SWP_NOCOPYBITS = &H100
Global Const WM_SWP_NOMOVE = &H2
Global Const WM_SWP_NOREDRAW = &H8
Global Const WM_SWP_NOREPOSITION = &H200
Global Const WM_SWP_NOSIZE = &H1
Global Const WM_SWP_NOZORDER = &H4
Global Const WM_SWP_SHOWWINDOW = &H40
 
Global Const WM_SW_MAXIMIZE = 3
Global Const WM_SW_MINIMIZE = 6
Global Const WM_SW_SHOWMINIMIZED = 2
Global Const WM_SW_NORMAL = 1
Global Const WM_SW_SHOWNORMAL = 1
Global Const WM_SW_RESTORE = 9
Global Const WM_SW_HIDE = 0
Global Const WM_SW_SHOW = 5
 
Global Const WM_HORZRES = 8
Global Const WM_VERTRES = 10
 
Dim i As Integer
Global iJustOpened As Integer
Dim iFormPosition As Integer
Global iFormPositioningMode As Integer
Global iFormTop As Integer
Global iFormLeft As Integer
 
 
 
 
Type WM_POINTAPI
        X As Long
        Y As Long
End Type
 
Type WM_Rect
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
 
Type WM_WINDOWPLACEMENT
        Length As Long
        flags As Long
        showCmd As Long
        ptMinPosition As WM_POINTAPI
        ptMaxPosition As WM_POINTAPI
        rcNormalPosition As WM_Rect
End Type
 
Declare Function WM_apiSetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Declare Function WM_apiGetParent Lib "user32" Alias "GetParent" (ByVal hWnd As Long) As Long
Declare Function WM_apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function WM_apiGetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long
Declare Function WM_apiGetDC Lib "user32" Alias "GetDC" (ByVal hWnd As Long) As Long
Declare Function WM_apiReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hWnd As Long, ByVal hdc As Long) As Long
Declare Function WM_apiGetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Declare Function WM_apiGetSystemMetrics Lib "user32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
Declare Function WM_apiGetWindowPlacement Lib "user32" Alias "GetWindowPlacement" (ByVal hWnd As Long, lpwndpl As WM_WINDOWPLACEMENT) As Long
Declare Function WM_apiIsZoomed Lib "user32" Alias "IsZoomed" (ByVal hWnd As Long) As Long
Declare Function WM_apiGetClientRect Lib "user32" Alias "GetClientRect" (ByVal hWnd As Long, lpRect As WM_Rect) As Long
Function xg_GetAccesshWnd() As Long
'Returns a handle to the main Access window
Dim hWnd As Long
Dim hAccessWnd As Long
hWnd = Screen.ActiveForm.hWnd
hAccessWnd = hWnd
'* Find the top window without a parent window.
While hWnd <> 0
    hAccessWnd = hWnd
    hWnd = WM_apiGetParent(hWnd)
Wend
 
xg_GetAccesshWnd = hAccessWnd
 
End Function


Sub xg_SizeWindow(sWindow As String, X As Integer, Y As Integer, cx As Integer, cy As Integer)
' Size the active form window, or the main Access window.
' Parameter sWindow:  "Active" - Size the active form window.
'                     "Access" - Size the main Access window.
'                 x:  left boundry for window (pixels)
'                 y:  top boundry for window
'                cx:  width of window
'                cy:  height of window
Dim iRtn As Integer
Dim hWndSize As Long
 
If sWindow = "Active" Then
    hWndSize = Screen.ActiveForm.hWnd
ElseIf sWindow = "Access" Then
    hWndSize = xg_GetAccesshWnd()
Else
    MsgBox "Invalid parameter passed to xg_SizeWindow = " & sWindow
    Exit Sub
End If
 
iRtn = WM_apiShowWindow(hWndSize, WM_SW_RESTORE)
 
Call WM_apiSetWindowPos(hWndSize, 0, X, Y, cx, cy, WM_SWP_NOZORDER Or WM_SWP_SHOWWINDOW)
 
End Sub

Function fSetAccessWindow(nCmdShow As Long)
'Usage Examples
'Maximize window:
'       ?fSetAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
'       ?fSetAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
'       ?fSetAccessWindow(SW_HIDE)
'Normal window:
'       ?fSetAccessWindow(SW_SHOWNORMAL)
'
Dim loX  As Long
Dim loForm As Form
    On Error Resume Next
    Set loForm = Screen.ActiveForm
    If Err <> 0 Then 'no Activeform
      If nCmdShow = WM_SW_HIDE Then
        MsgBox "Cannot hide Access unless " _
                    & "a form is on screen"
      Else
        loX = WM_apiShowWindow(hWndAccessApp, nCmdShow)
        Err.Clear
      End If
    Else
        If nCmdShow = WM_SW_SHOWMINIMIZED And loForm.Modal = True Then
            MsgBox "Cannot minimize Access with " _
                    & (loForm.Caption + " ") _
                    & "form on screen"
        ElseIf nCmdShow = WM_SW_HIDE And loForm.PopUp <> True Then
            MsgBox "Cannot hide Access with " _
                    & (loForm.Caption + " ") _
                    & "form on screen"
        Else
            loX = WM_apiShowWindow(hWndAccessApp, nCmdShow)
        End If
    End If
    fSetAccessWindow = (loX <> 0)
End Function

'************Code End***********

<Place this code on your Form load>

'**********Code start*******
Private Sub Form_Load()
DoCmd.Restore

Dim X As Integer, Y As Integer, cx As Integer, cy As Integer

'resize window
X = 25 ' this position the windows at your wish
Y = 25

cx = 588 ' make the window what size you wish
cy = 950
 
xg_SizeWindow "active", X, Y, cx, cy
End Sub

'**********Code end************



0
 
LVL 1

Expert Comment

by:moralju
ID: 10955928
YOu can also place this in your Form open property and make the Access Container Maximize

'Maximize Access window
fSetAccessWindow (WM_SW_MAXIMIZE)
0
 
LVL 34

Expert Comment

by:flavo
ID: 10955941
or you could do it the easy way.. re my first post
0
 
LVL 1

Expert Comment

by:moralju
ID: 10955979
Flavo, I really think its up to pmcontractor to decide.
debating over who has a better option is a waste of space and time.

As per EE culture..
0
 
LVL 8

Expert Comment

by:Benjamin_Luk
ID: 10956648
Just using Movesize action is enough

You can use the MoveSize action to move or resize the active window.

Setting

The MoveSize action has the following arguments.

Action argument      Description
Right      The new horizontal position of the window's upper-left corner, measured from the left edge of its containing window. Enter the position in the Right box in the Action Arguments section of the Macro window.
Down      The new vertical position of the window's upper-left corner, measured from the top edge of its containing window.
Width      The window's new width.
Height      The window's new height.

Best Regards


Ben
0

Featured Post

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question