Open MS Access window in a certain position and size (1 Viewer)

rodin

Registered User.
Local time
Today, 07:32
Joined
Aug 25, 2006
Messages
12
Hi,

I would like to open the MS Access Window in a certain position and size.

Somehow similar to open a form when using:
- to set the position and size:

Private Sub Form_Load()
Form.Move Left:=11500, Top:=6500, Width:=7000, Height:=6000
End Sub

I would like to open the MS Access Window within the screen area at a certain location, and having a certain size.
Is there any option in the Access Menu, or I can write some code, and where has to be written, so when I double click on the *.mdb file, the MS Access Window will open where I want and the size I want.

Thank you.
 

rodin

Registered User.
Local time
Today, 07:32
Joined
Aug 25, 2006
Messages
12
Hi,

Thanks for your replay. I have thought about MoveSize command, but I don't know how to use it in this case.

You can use the MoveSize action to move or resize the active window. I don't know how to make MS Access Window active, and have this command work when I double click on the *.mdb file.
This command can be used in a macro, or in Visual Basic. I tried in a macro, but works for the active window which is never the MS Access Window. I don't know how to use it in VB, because I don't know the specific name for the MS Access software Window.

Any suggestions?

Thank you.
 

rodin

Registered User.
Local time
Today, 07:32
Joined
Aug 25, 2006
Messages
12
Hi,

I don't know where to write the code (combaining OMain and MoveSize) and actualy how this code will be.
Do I have to create a function, or work from a procedure, and if this is the case, what procedure?

Any hints?

Thank you!
 

edtab

Registered User.
Local time
Today, 15:32
Joined
Mar 30, 2002
Messages
257
I have used the movesize command in the "on load" event of one
of my forms. I have also used it in the "On click" event of a command
button.
 

rodin

Registered User.
Local time
Today, 07:32
Joined
Aug 25, 2006
Messages
12
Hi,

Bellow is a code that I found on this forum, and which works. Follow the steps described.

****************************************

API: Manipulate Access Window
Author(s)
Dev Ashish


(Q) How do I maximize or minimize the main Access Window from code?

(A) Pass one of the declared constants to the function fSetAccessWindow.

This same function can also be used to completely hide Access window and just show your form on the desktop. Make the form popup and from it's Open Event, call the fSetAccessWindow function with SW_HIDE as the argument.

Warning: If you're hiding the main Access window, make sure your error handlers are good. Because with the window hidden, if an error is raised, pressing "End" on the Error window will NOT make Access window visible and you will be left with just the form open. A recommended method is to make a call to fSetAccessWindow with SW_SHOWNORMAL from your error handlers.
If, for some reason, the Access window does not show itself, then you can always close the mdb from the Task List, available in Win 95 with Control-Alt-Delete (once) and under NT, by right clicking on the Taskbar and selecting Task Manager, by selecting the mdb and clicking End Task.

Code:
'************ Code Start **********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3


Private Declare Function apiShowWindow Lib "user32" _
    Alias "ShowWindow" (ByVal hwnd As Long, _
          ByVal nCmdShow As Long) As Long

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 = SW_HIDE Then
        MsgBox "Cannot hide Access unless " _
                    & "a form is on screen"
      Else
        loX = apiShowWindow(hWndAccessApp, nCmdShow)
        Err.Clear
      End If
    Else
        If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
            MsgBox "Cannot minimize Access with " _
                    & (loForm.Caption + " ") _
                    & "form on screen"
        ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Then
            MsgBox "Cannot hide Access with " _
                    & (loForm.Caption + " ") _
                    & "form on screen"
        Else
            loX = apiShowWindow(hWndAccessApp, nCmdShow)
        End If
    End If
    fSetAccessWindow = (loX <> 0)
End Function

'************ Code End **********
 
Last edited by a moderator:

dholcomb

New member
Local time
Today, 10:32
Joined
Aug 12, 2013
Messages
1
I wanted to have my Access file open up in a window that took up the entire right half of my desktop. After searching this and a few other forums, this is what I came up with. I put the below into a separate module, and called the new function ScreenRL(TRUE) from an AutoExec Macro, and voila!

The SizeAccess() function can also easily be called to re-position and re-size the access window as desired

Code:
Option Compare Database
Option Explicit

Declare Function GetSystemMetrics32 Lib "user32" _
    Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

Declare Sub SetWindowPos Lib "user32" (ByVal hWnd&, _
ByVal hWndInsertAfter&, _
ByVal X&, ByVal Y&, ByVal cX&, _
ByVal cY&, ByVal wFlags&)

Global Const HWND_TOP = 0 'Moves MS Access window to top
'of Z-order.

'Values for wFlags.

Global Const SWP_NOZORDER = &H4 'Ignores the hWndInsertAfter.


Function SizeAccess(cX As Long, cY As Long, cWidth As Long, cHeight As Long)

Dim h As Long
'Get handle to Microsoft Access.
h = Application.hWndAccessApp

'Position Microsoft Access.
SetWindowPos h, HWND_TOP, cX, cY, cWidth, cHeight, SWP_NOZORDER
Application.RefreshDatabaseWindow
End Function

Function ScreenRL(cRight As Boolean)

'pick up the current monitor height and width
Dim w As Long, h As Long
    w = GetSystemMetrics32(0) ' width in points
    h = GetSystemMetrics32(1) ' height in points
    w = w / 2
    h = h - 30

'set the Access window Size using SizeAccess function
If cRight = True Then
    'position the access widow to take up the Left half of the desktop
    SizeAccess w, 0, w, h
    Else 
    'position the access widow to take up the Left half of the desktop
    SizeAccess 0, 0, w, h
    End If


End Function
 

govuser1

Registered User.
Local time
Today, 07:32
Joined
May 14, 2012
Messages
11
I am already using the code above to resize the window but I don't want to set position. i.e. let it reload the access window wherever it was the last time it was closed.

What can I change in the code above to ensure that the position of the window is not adjusted.
 

Users who are viewing this thread

Top Bottom