MS-Access: How to open form in same location/size

2019-07-11 04:26发布

问题:

I am creating a database application using Access 2003 that will be run as a stand-alone application (i.e. using the Access runtime). I have a main form that opens to a pre-defined location and size and I would like to control where any other forms open.

I would like to open additional forms at the same location and size as the main form. I could use the "autocenter" property but I would like the user to be able to move the form wherever they like and have the new form appear at that location. Only one form will be open at any one time since I close the previous form when opening a new form.

Any suggestions on how to accomplish this with VBA? Thanks.

回答1:

You can read form property values to determine the first form's position and size.

Debug.Print Me.WindowLeft, Me.WindowTop, Me.WindowWidth, Me.WindowHeight

The next form can match those values with the Move method.

Me.Move Left:=0, Top:=0, Width:=400, Height:=300

You would have to decide on a method to pass the values from the first to the second form.

  1. as properties of a custom class
  2. as OpenArgs for the second form
  3. use a table to store the values


回答2:

Have you considered MoveSize?

http://msdn.microsoft.com/en-us/library/bb238004(office.12).aspx