By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,456 Members | 1,472 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,456 IT Pros & Developers. It's quick & easy.

Can FormB tell FormA to move/resize?

P: 31
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
Apr 6 '10 #1

✓ answered by Delerna

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

Expand|Select|Wrap|Line Numbers
  1.    Private Sub Command1_Click()
  2.       ' This code is on FormB
  3.  
  4.       Forms![FormA].SetFocus
  5.       DoCmd.MoveSize 100, 100, 1000, 1000
  6.       Me.SetFocus
  7.    End Sub
  8.  

Share this Question
Share on Google+
3 Replies


Delerna
Expert 100+
P: 1,134
set focus to the form you want to resize
before using docmd

Expand|Select|Wrap|Line Numbers
  1.    Private Sub Command1_Click()
  2.       ' This code is on FormB
  3.  
  4.       Forms![FormA].SetFocus
  5.       DoCmd.MoveSize 100, 100, 1000, 1000
  6.       Me.SetFocus
  7.    End Sub
  8.  
Apr 6 '10 #2

patjones
Expert 100+
P: 931
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:

Expand|Select|Wrap|Line Numbers
  1. Dim intLeftFormA As Integer
  2. 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

Expand|Select|Wrap|Line Numbers
  1. intLeftFormA = Me.WindowLeft
  2. intTopFormA = Me.WindowTop
  3.  
  4. DoCmd.MoveSize 5, 5
  5. DoCmd.OpenForm "frmB", acNormal
  6.  

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

Expand|Select|Wrap|Line Numbers
  1. Dim frm As Form
  2. Set frm = Forms!frmA
  3.  
  4. DoCmd.Close acForm, "frmB", acSaveNo
  5. frm.Move intLeftFormA, intTopFormA
  6.  

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
Apr 7 '10 #3

P: 31
Delerna,

Your method worked great! Quick and easy.

Thanks for your help!

andy
Apr 7 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.