Maximize Form (1 Viewer)

Eljefegeneo

Still trying to learn
Local time
Yesterday, 19:38
Joined
Jan 10, 2011
Messages
904
I have the following code that opens a form in a second DB to a specific record.
Code:
  [I]'---Open related form in Main DB[/I]
  Dim db2 As Object
  Set db2 = GetObject("C:\Users\jbern\Desktop\Billing\DBMain.accdb", "Access.Application")
  [I]'--close the LogIn Form so user does not have to log in[/I]
  db2.DoCmd.Close acForm, "frmLogin"
  [I]'Open the Main Menu so user can close the DB after they are finished[/I]
  db2.DoCmd.OpenForm "frmOpenFirst3"
  db2.DoCmd.OpenForm "frmSales"
  db2.DoCmd.SelectObject acForm, "frmSales"
  db2.DoCmd.Maximize
  db2.Forms("frmSales").Filter = "[SequenceNumber] = " & Me.SequenceNumber
  db2.Forms("frmSales").FilterOn = True
  Set db2 = Nothing
It works fine even if the second Access DB is open. It seems to want to open a second DB not maximized when another DB is open. That is, it only shows about half the page of the form. I have to click on the Maximize button in the upper right hand corner to get it to full size.

I want the second DB when it opens to show the form "frmSales" Maximized.


And I did try inserting the code to Maximize the form on load. No luck there either.
 
Last edited:

Eljefegeneo

Still trying to learn
Local time
Yesterday, 19:38
Joined
Jan 10, 2011
Messages
904
Found something that might work.



Code:
db2.DoCmd.RunCommand acCmdAppMaximize
[code]


Seems to do the job.  Have to see if it works on the network dB.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:38
Joined
May 7, 2009
Messages
19,228
copy and paste this in a Standarrd Module.
this will maximize access window.

Code:
Option Compare Database
Option Explicit


'==============================
'  CONSTANTS FOR DBASE WINDOW
'==============================
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
 
'==========================
'  DBASE WINDOW FUNCTIONS
'==========================
#If VBA7 Then
    #If Win64 Then
        Public Declare PtrSafe Function IsWindowVisible Lib "user32" _
                (ByVal hwnd As LongPtr) _
            As Long
        Public Declare PtrSafe Function ShowWindow Lib "user32" _
                (ByVal hwnd As LongPtr, _
                ByVal nCmdShow As Long) _
            As Long
    #Else
        Public Declare PtrSafe Function IsWindowVisible Lib "user32" _
                (ByVal hwnd As Long) _
            As Long
        Public Declare PtrSafe Function ShowWindow Lib "user32" _
                (ByVal hwnd As Long, _
                ByVal nCmdShow As Long) _
            As Long
    #End If
#Else
    Public Declare Function IsWindowVisible Lib "user32" _
            (ByVal hWnd As Long) _
        As Long
    Public Declare Function ShowWindow Lib "user32" _
            (ByVal hWnd As Long, _
            ByVal nCmdShow As Long) _
        As Long
#End If
'============================
' FORM MANAGEMENT FUNCTIONS
'============================
#If VBA7 And Win64 Then
Public Function fAccessWindow(Handle As LongPtr, Optional Procedure As String, _
    Optional SwitchStatus As Boolean, Optional StatusCheck As Boolean) As Boolean
#Else
Public Function fAccessWindow(Handle As Long, Optional Procedure As String, _
    Optional SwitchStatus As Boolean, Optional StatusCheck As Boolean) As Boolean
#End If
'****************************************************************************************
'* Purpose:  Controls the behavior and appearance of the Daatabase window               *
'*           residing on the form, and hence, we reduce the overall size of the FE DB.  *
'* Accepts:  Procedure -    describes the behavior requested                            *
'*           SwitchStatus - (optional) instructs the procedure to switch the current    *
'*                          status of the DB Window                                     *
'*           StatusCheck -  (optional) allows the procedure to check the current status *
'*                          of the DB window to determine whether or not to initiate a  *
'*                          change                                                      *
'****************************************************************************************
On Error GoTo EH
    Dim dwReturn As Long
    If Procedure = "Hide" Then
        dwReturn = ShowWindow(Handle, SW_HIDE)
    End If
    If Procedure = "Minimize" Then
        dwReturn = ShowWindow(Handle, SW_SHOWMINIMIZED)
    End If
    If Procedure = "Normal" Then
        dwReturn = ShowWindow(Handle, SW_SHOWNORMAL)
    End If
    If Procedure = "Show" Then
        dwReturn = ShowWindow(Handle, SW_SHOWMAXIMIZED)
    End If
    If SwitchStatus = True Then
        If IsWindowVisible(hWndAccessApp) = 1 Then
            dwReturn = ShowWindow(Handle, SW_HIDE)
        Else
            dwReturn = ShowWindow(Handle, SW_SHOWMAXIMIZED)
        End If
    End If
    If StatusCheck = True Then
        If IsWindowVisible(Handle) = 0 Then
            fAccessWindow = False
        End If
        If IsWindowVisible(Handle) = 1 Then
            fAccessWindow = True
        End If
    End If
    Exit Function
EH:
    MsgBox "There was an error resetting the Database Window!  " & _
        "Please contact your Database Administrator.", vbCritical, "Error!"
    Exit Function
End Function

after opening the second db using getObject(), you call fAccessWindow():
Code:
...
Set db2 = GetObject(.....)
Call fAccessWindow(db2.hWndAccessApp, "Show")
...
 

Eljefegeneo

Still trying to learn
Local time
Yesterday, 19:38
Joined
Jan 10, 2011
Messages
904
Finally got a chance to test it. Thank you.

Only trick now which I did not see when attempting this is if the second db is open is that I either have to close it before going to a new record or rush opening a second copy of the second db. Will have to investigate this before I update the DB.
 

Users who are viewing this thread

Top Bottom