Can FormB tell FormA to move/resize?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tetsuo2030
    New Member
    • Apr 2010
    • 31

    #1

    Can FormB tell FormA to move/resize?

    Greetings all,

    I'm working on a database that has a series of forms (FormA, FormB, FormC, FormD). Each time I click a button on one form, it opens the next and moves the original form to the corner of the screen using DoCmd.MoveSize. I did this for purely aesthetic reasons: instead of minimizing the forms or making them invisible, I organize them off-center so their captions show.

    Then someone challenged me to return those forms to their original position on the close of the previous form (again, for purely aesthetic reasons). And here is where I ran into some trouble: the DoCmd.MoveSize can be applied to a button click or OnOpen, but that's for the current form. What I was hoping to do was find a way to click a button on FormB that would tell FormA to move to another position/size. Is this feasible?

    I messed with the SetFocus command but couldn't make it work. I even rigged it so that on the close of FormB, it closed FormA too and then immediately re-opened FormA (which has its own particular DoCmd.MoveSize parameters OnOpen); however, that only worked when toggling between two forms: remember, if OnClose of FormC, FormB closes and reopens, and if OnClose of FormB, FormA closes and reopens, then, in cascading fashion, the close of FormC will close FormA and reopen it according to its own OnOpen position/size. Besides, that's not what I really want to happen.

    Any ideas?

    andy
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    set focus to the form you want to resize
    before using docmd

    Code:
       Private Sub Command1_Click()
          ' This code is on FormB
    
          Forms![FormA].SetFocus
          DoCmd.MoveSize 100, 100, 1000, 1000
          Me.SetFocus
       End Sub

    Comment

    • patjones
      Recognized Expert Contributor
      • Jun 2007
      • 931

      #3
      Hi -

      I'll show you how to do this with two forms; you can apply the procedure to as many forms as you want though.

      In the VBA window, go Insert > Module. This will create a new code module. You'll declare two variables in it:

      Code:
      Dim intLeftFormA As Integer
      Dim intTopFormA As integer

      These two variables are global; they can be seen by all other modules in your project. In the OnClick event for the button in form A, put

      Code:
      intLeftFormA = Me.WindowLeft
      intTopFormA = Me.WindowTop
      
      DoCmd.MoveSize 5, 5
      DoCmd.OpenForm "frmB", acNormal

      The first two lines store the position of the form in the global variables before you move it...for later use. The third line moves form A nearly to the upper-left corner. The fourth line obviously opens form B. In the button on form B that closes form B and will re-position form A, put

      Code:
      Dim frm As Form
      Set frm = Forms!frmA
      
      DoCmd.Close acForm, "frmB", acSaveNo
      frm.Move intLeftFormA, intTopFormA

      You have to declare a form object in order to be able to use all the various form methods, which is what the first two lines are about. I tested this out quickly and it seems to work okay. Let me know how it goes!

      Pat

      Comment

      • tetsuo2030
        New Member
        • Apr 2010
        • 31

        #4
        Delerna,

        Your method worked great! Quick and easy.

        Thanks for your help!

        andy

        Comment

        Working...