The Access Wizard Newsletter Tips, Tricks, and Traps for Access Users and Developers
July 2010

Putting a Form Where You Want: The MoveSize Command

Our favorite weekend activities when my kids were pre-teens included hiking, going to places like the circus, or going on factory tours. One of the more memorable factory tours was the Crane Paper Company in Western Massachusetts.

Both my boys were excited to see the place where they make paper for our US currency. We arrived just after a busload of tourists and, as a result, had a tough time getting good seats for the presentation. We had several options; we could either try to increase our size (think of getting a booster seat - not very practical), decrease the size of person in front of us (asking them to scrunch down - not very nice), or move to a spot where we could get a better view.

We took the later course and moved to better seats where we learned the ins and outs of paper making. It was a day that the kids found enchanting, and I was happy with its educational value.

Being able to control the size and placement of something can be either trivial (where to plant the begonias) or critically important (where the 50 foot pine in your front yard is cut so that it doesn't crash into your house). In Access applications, most of the time the default position of your form on the screen is just fine.

In some cases though, you want to have more control. Although you can manually move the form, sometimes you want it to always appear in a certain spot; for instance, if may want a pop-up form (a special kind of form that stays on top of other forms) to always open in a certain spot. This is very helpful when you want one form to be available for a reference while you are working on another form.

This month, we will take a look at a method for placing a form exactly where you want it by using the MoveSize command.

In this Issue
  • Tip of the Month - How to Use Auto Complete Typing While In Code
  • The Basics
  • Niceties

  • The Basics

    The syntax for the MoveSize command is straightforward. If you are going to be working on the active form (the form that currently has the focus), you would use the following code:

    Docmd.MoveSize Right, Down, Width, Height

    The right, down, width, and height parameters are all optional provided, of course, at least one of them is supplied. For example, if you want to make him sure that your form is at the top left corner of the screen, you would enter the following:

    Docmd.MoveSize 0, 0

    This would essentially take your form and position at the very top left corner of the window. If you put this command in the on open an event of the form, it will place and size itself when the form opens.

    There is one little kicker here. Life would be easy if these units were in inches or even centimeters. Unfortunately, these dimensions are in twips, a measure used frequently by programmers when working with placement and size on computer screens. There are some very good reasons that twips are used rather than inches or centimeters, but it's fairly technical stuff and, frankly, boring. The important thing to know is that 1440 twips equals 1 inch.

    Once you have this conversion ratio, a little bit of simple arithmetic will allow you to place and size your form.


    You can use this command not only for the active form, but for any form that is currently open by first referencing the form. You could accomplish this with the following code:

    Dim frm as form
    Set frm = "YourFormName"
    Frm.movesize Right, Down, Width, Height

    What's interesting at this point is that, because you're no longer dealing with the current form, you can use a control on another open form as a reference for where you want your target form to end up.

    For example, let's say that you had a certain text box called myTextBox in the current form and that you wanted the new form to be placed at the same height and just to the right of myTextBox.

    In this case, you would essentially say something along the following lines:

    Dim frm as form
    Dim tgtctl as control
    Dim lngTop as long
    Dim lngRight as long

    Set frm = "YourFormName"
    Set ctl = screen.activeformname.controls(myTextBox)
    lngRight = ctl.left + ctl.width
    lngTop = ctl.top

    Frm.movesize lngRight, lngTop

    This would essentially place your newly open form at the same height, and at the right edge of your text box.

    A couple things to note: A control has a left property but not a right property, so notice that, for the right side placement of your form, you have to reference the left side of the control and then add the control width.

    The best way to understand how to use this command is to experiment a bit. Although it is not a technique that you will use every day, when you do have the need for precise placement, it really comes in handy.

    Tip of the Month - How to Use Auto Complete Typing While In Code

    Frequently, when you are writing code, Access will present you with options when you hit the period key. Once the option is available to you, you can easily choose to auto complete your typing.

    Although this option pops up when you hit the period key, there's a trick to get it to help you even earlier. After you've typed several characters, press and hold the control key and then hit your space-bar. At that point, if there's more than one reasonable possibility for what you've begun typing, Access will present you with a list of possibilities and you can choose the one you want. If there is only one possibility, Access will choose that for you immediately.

    This is a nifty trick that takes a lot of the drudgery out of correctly typing obscure commands; it also allows you to take a guess at something that you might not be completely sure of, and see if it is something that works.

    Quick Links...

    Custom Software Home

    Access Wizard Archives

    Our Services

    Join our mailing list!

    Custom Software | Copyright Custom Software All Rights Reserved | Westford | MA | 01886