How do you control the way Access forms open?

Posted on 2011-04-21
Last Modified: 2012-05-11
When the current database window is maximized within Access' main window, any form opens up maximized, whether by double-clicking its name in the forms pane or by using the DoCmd.OpenForm in a VBA macro.  When the current database window is not maximized within Access' main window, forms appear to open up the way they were last saved... I think.  Is there a way to have total control over this?
Question by:musgah
    LVL 75

    Accepted Solution

    You can use these commands in the Form Load event of each Form:

    Private Sub Form_Load()
        DoCmd.Maximize   ' one or the other of these two
        '  DoCmd.Restore
    End Sub

    LVL 26

    Assisted Solution

    Form Load, as mx said.

    I have a modal form that, when I develop on dual monitors, had a habit of squashing itself skinny and flat invisible on single monitor machines.
    I now place and size it on open

    With DoCmd
        .SelectObject acForm, "frmJobID"
        .MoveSize 0, 0 'this puts the form in the upper left corner
    End With
    Me.Width = 6.5 * 1440 ' 6.5 inches x 1440 twips per inch
    Me.InsideHeight = 2.125 * 1440
    Me.InsideWidth = 6.25 * 1440
    LVL 26

    Assisted Solution

    Replace "frmJobID"  with your form's name
    Replace the decimals with your prefered size in inches
    LVL 2

    Assisted Solution

    If you are using either Access 2007 or Access 2010 then you will need to make sure the following setting is made:

    With the Database loaded, go to File|Options|Current Database and, under the Document Window Options Section,  select the "Overlapping Windows" Option Button" rather than "Tabbed Documnents" and don't forget to click the OK button after making the change.  

    Essentially, if you have a non-maximised form (e.g. Main Menu or Switchboard)... and you want to open another form, that will be maximised, whilst leaving the original form open underneath, you can put the VBA code "DoCmd.Maximize" in the second form's Open Event (or Load Event,as DatabaseMX suggests).  

    When you want to close-down the second form, you can place the VBA code "DoCmd .Restore" in the Close Event (or Load Event)... This ensures that the initial (Main Menu) form doesn't appear in Maximized state but, rather, exactly as it was when originally opened.

    If the initial form is Maximized and the second form needs to appear, Non-Maximised, over the top of the initial form, then you can set the Auto Center and Auto Resize (Format Tab) Properties to Yes... and, if required, the Pop Up and Modal (Other Tab) Properties to Yes.

    If the first form needs to be unseen whilst the second form is open, then the second form's Open Event can contain the VBA code "Forms![<FormName>].Visible = False" and the Close Event will contain the VBA code "Forms![<FormName>].Visible = True"

    Placing the  code in the Open-Close or Load-Unload Events (I've never found that much difference) will ensure that the change in size works smoothly  - For reference the opening/closing sequence of events for a form is: Open>Load>Activate........Deactivate>Unload>Close,

    Hope that's not too confusing... and that it helps.

    Glen Ashton


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

    730 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now