Results 1 to 6 of 6
  1. #1
    newbieX is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    111

    How to always maximize form when visible?

    On Main Form (frmMain)



    Code:
    Private Sub Form_Activate()
        DoCmd.Maximize
    End Sub
    
    Private Sub btn1_Click()
        DoCmd.OpenForm "PW_Entry", acNormal, , , , , "Password"
        Forms!frmMain.Visible = False
    End Sub
    On PW_Entry Form

    Code:
    Private Sub cmdClose_Click()
        Forms!frmMain.Visible = True
        DoCmd.Close acForm, "PW_Entry"
    End Sub
    There are only two buttons on the PW_Entry form: Close and Continue. Continue closes PW_Entry form and opens a different form. Close makes the frmMain visible and closes the PW_Entry form. My expectation is that when I make the frmMain visible and close the DataEntry form when clicking the Close button that the frmMain form will automatically maximize but this is not happening. No other forms are open.

    How do I keep the frmMain always maximized when visible if not via the Activate event?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Theres no need to make the main form invisible. The new form will lay over top of it.
    Then when you close it, main form is visible and maximized.

  3. #3
    newbieX is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    111
    Fair point certainly worth further consideration but assuming I want to make it not visible when opening another form for whatever reason, how do I programmatically make the form always maximized when visible. What in the above code am I missing? One more thing. PW_Entry form is basically there to capture parameter. It's Popup property = Yes and Modal = No.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Maybe something like

    Forms!frmMain.Visible = True
    DoCmd.Close acForm, "PW_Entry"
    Forms!frmMain.setfocus
    docmd.maximize

    The reason I would try it in this order is because Docmd will only work on the object it has focus on and I can't recall the code needed to close a form without it.

  5. #5
    newbieX is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    111
    Quote Originally Posted by ItsMe View Post
    Maybe something like

    Forms!frmMain.Visible = True
    DoCmd.Close acForm, "PW_Entry"
    Forms!frmMain.setfocus
    docmd.maximize

    The reason I would try it in this order is because Docmd will only work on the object it has focus on and I can't recall the code needed to close a form without it.
    That did it.

    Question. I have always assumed that once you close a form, all the code below the DoCmd.Close command ceases to execute since the form closes and thus cannot reference its code; hence I never put any commands after the DoCmd.Close statement. I take it this is not true since your code worked. Big eureka moment if so, although it totally throws my understanding of how code moves through a script into a tizzy. Any good link to send me to to help me understand this new kink in my understanding of coding? Thanks.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by newbieX View Post
    ... I have always assumed that once you close a form, all the code below the DoCmd.Close command ceases to execute since the form closes and thus cannot reference its code...
    I used to think that way too. I don't recall who pointed it out to me. But, someone on this forum explained that the code will continue to execute until the end of the code block. It was either Paul or Linq. So, I do not have any footnotes. However, if you think about it, it's not difficult to put it into perspective. You used the form's fully qualified name to access the method. Once you got the ball rolling, it will finish until it reaches the End Sub or End Function line (as long as there is not an exception/error).

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 16
    Last Post: 03-26-2015, 08:35 PM
  2. Replies: 4
    Last Post: 11-04-2014, 07:35 PM
  3. Replies: 9
    Last Post: 06-03-2014, 09:33 AM
  4. Replies: 6
    Last Post: 02-08-2014, 10:04 AM
  5. Replies: 2
    Last Post: 01-06-2011, 04:38 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums