Link to home
Start Free TrialLog in
Avatar of DanielAttard
DanielAttardFlag for Canada

asked on

Maximize program window at launch?

Can someone please tell me how to ensure that my program window is maximized every time the program is launched?  

This was recently working (by default) with my Access2002 application, but when I upgraded to Access2003, I wanted to stop seeing the "Security Warning", so I found a script to automate the process of opening the application without seeing the warning.  The following script accomplishes the objective of avoiding the "Security Warning", however, it causes my program to launch in various window states, never maximized which is what I want:
********************************************************************
Const cDatabaseToOpen = "C:\Documents and Settings\home\My Documents\MyApp.mdb"
On Error Resume Next
Dim AcApp
Set AcApp = CreateObject("Access.Application")
If AcApp.Version >= 10 Then
     AcApp.AutomationSecurity = 1 ' msoAutomationSecurityLow
End If
AcApp.Visible = True
AcApp.OpenCurrentDatabase cDatabaseToOpen
If AcApp.CurrentProject.FullName <> "" Then
     AcApp.UserControl = True
Else
     AcApp.Quit
     MsgBox "Failed to open '" & cDatabaseToOpen  & "'."
End If
*************************************************************
Is there anything in this code that might be causing my app to launch in a non-maximized state?  How can I ensure the app is maximized every time?  Thanks
SOLUTION
Avatar of flavo
flavo
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DanielAttard

ASKER

Thanks for the quick response Dave!  

I understand 80% of what you're telling me.  Help me remember what I should know by know!  Where would I put that macro and how would I ensure that it runs at startup?  How does program know what I am referring to?  A form, report or the program itself?
Ok..

1. Create a new module and copy the function in {from above}

2. Then create a new macro.  You will see something that looks like a table.  Click on the top left cells (A1 in excel).  From the drop down box, select RunCode.

3. Down the bottom will be a textbox asking for "Function name".  Put in myStartUp().

4. Save the macro as AutoExec.   The autoexec macro will be the first thing that is run when the app opens.

>> How does program know what I am referring to?

Yes, this can be a bit of a problem after the app is open, and trying to maximise various windows (Docmd.Max max's the current window).  But in your case this will be ok.  Seeing the AutoExec macro runs before any forms etc.. are open, the only thing it can maximise is the main Access window.

More help??

Dave
Almost there Dave,

Implemented your suggestions and now what seems to be causing the problem is something to do with the frmSplash that is displayed as the form to display at startup as specified in the Startup dialog options box.

Your code appears to be maximizing frmSplash (which is a login screen), and then after the user logs-in, the databased window appears behind, in the non-maximized state I complained about initially.

Take out the code / optio that is loading your splash screen

Then in the autoexec macro add after the Run Code line, OpenForm and select "frmSplash"

Dave
Sorry for being a pest about this Dave, but now it is back to the way it was originally.  I implemented your very obvious suggestion, to open frmSplash after the RunCode first line (DoCmd.Maximize) of the AutoExec macro.  

The app window is not maximized when launched.  I have a screen snapshot that I could email you.  
Avatar of BillPowell
BillPowell

Perhaps you would consider changing the shortcut properties for the db to run in maximized state.  This will accomplish what you need.  Right click the shortcut, select properties,in the shortcut tab select maximized from the run combo box.

Regards,

Bill
Thanks for the suggestion Bill.  I checked what you said, and the shortcut already is set to run maximized.  The only problem is that the shortcut is not actually referring to the database itself, it is referring to the code written at the top of this thread.  That code effectively bypasses the security warning at startup for Access2003.

Still can't get my app to launch maximized from the get-go.
Hi DanielAttard,

try

   DoCmd.Movesize <right>, <down>, <width>, <height>

Where the values are in Twips,  one inch=1440 Twips.


Hope this helps

Jaffer
Avatar of Rey Obrero (Capricorn1)
DanielAttard

Check this link
How do I maximize or minimize the main Access Window from code
http://www.mvps.org/access/api/api0019.htm

Here is how to do this

a. Create a Module and place this codes
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3

b. On your flash form  frmFlash VBA window place this codes

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

Private Sub Form_Open(Cancel As Integer)
    fSetAccessWindow (3)

End Sub

Private Sub Form_Timer()
    DoCmd.Close
    DoCmd.OpenForm "YourStartForm", , , , , acHidden
End Sub


Function fSetAccessWindow(nCmdShow As Long)
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




DanielAttard
May I ask where you place the script that you mention above.

regards,
rey;-)
Hi Rey,

Thanks for the suggestion.  You asked where I placed the script referred to above.  For now, that script is just sitting on my desktop.  When I double-click the script, it by-passes security warning and launches my app, but the app is not maximized.  I want to try your suggestion, but I don't understand your point (b) above.  Where exactly would I put that code?


My app currently has a frmSplash that I use to require users to login.

Thanks for your help.
You have to place the codes on VBA window of frmSplash.
To get there select from Database window
Forms>frmSplash then press Alt and F11 [Alt+F11]

Option Compare Database                              '*** this is at the top most of the window normally it is present
Private Declare Function apiShowWindow Lib "user32" _
    Alias "ShowWindow" (ByVal hwnd As Long, _
          ByVal nCmdShow As Long) As Long
'----------------------------------------------------------
'The rest of the codes goes here

Private Sub Form_Open(Cancel As Integer)
    fSetAccessWindow (3)

End Sub

Function fSetAccessWindow(nCmdShow As Long)
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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you Peter.  Your suggestion did the trick!  Works beautifully now.  

Thanks also to Flavo for putting me on the right path.  
Sorry i didnt get back.. (long weekend in Oz).  Swear i tested it here at work and it worked fine (A97).  But i did test it at home (A2003) and it didnt work.. ??  Interent was playing up over the w/e.

Good luck with the rest of yuor app!

Dave