How to Set Window width and height with VB?

AAlpha1 used Ask the Experts™
I set up a form as pop up window. The window does not open with the saved width and height.
How can I set those properties on Form Load? (or on the property sheet)


Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You can use the Move method for that:
FormReference.Move(Left, Top, Width, Height)
expression    Required. An expression that returns one of the objects in the Applies To list.

Left   Required Variant. The screen position in twips for the left edge of the object relative to the left edge of the Microsoft Access window.

Top   Optional Variant. The screen position in twips for the top edge of the object relative to the top edge of the Microsoft Access window.

Width   Optional Variant. The desired width in twips of the object.

Height   Optional Variant. The desired height in twips of the object.

Note: 1440 Twips = 1 inch

Private Sub Form_Load()
Me.TimerInterval = 10   'Give form time to open before applying Move Method.
End Sub

Private Sub Form_Timer()
    Me.TimerInterval = 0
    Forms![Superbill Large].Move 0, 0, 11503, 5610   '11999
End Sub


Thanks Mushi. I tried several of the suggestions described in the Links you provided. Most did not work. None showed haoe to fix the size of the window on form load.

Nelson: Here's the code I tried:
Private Sub Form_Load()
'   Give form time to open before applying Move Method.
    Me.TimerInterval = 10
'    FormReference.Move(Left, Top, Width, Height)
'   '11999    1440 Twips = 1 inch
    Forms![fCosts].Move (0, 0, 11503, 5610)       ' HERE I GET AN ERROR: EXPECT =  SYNTAX ERROR
End Sub                                                              '  OR : EXPECT =

This looks like what I need; once we get the syntax right. BTW, it's a split form. I don't know if it makes a difference.

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!


Nelson, It worked.
Here's the command that does not give a syntax error:

 Change: FormReference.Move(Left, Top, Width, Height)
To:          Forms![fCosts].Move 9200, 2850, 9900, 8640        Don't use the parentheses

The other change that clinched it: In the Access Options/Current database/Document Window Options: Select Overlapping Windows.

Thanks a lot for the help.

<Don't use the parentheses>
If you use the parentheses, VB expects the function to return something so you would use
Dim FakeVariable
FakeVariable = Forms![fCosts].Move (0, 0, 11503, 5610)
even though I don't think the Move method returns anything.

If you don't want the function to return anything, remove the parentheses (as my example displayed):
Forms![fCosts].Move 9200, 2850, 9900, 8640

BTW: if the code is in the form's object module, you can use the "Me" shortcut:
Me.Move 9200, 2850, 9900, 8640
which would be a few Microseconds faster.


FYI, when I changed the Document Window Options (Access Options) back to Tabbed Documents, with no other changes, the form window sizing changed! It's still acceptable.
From what I've read so far, Tabs and precise window sizing are not really compatible. It sure would be nice if they were.

Thanks again for the help.


Comments already posted in the discussion. Thanks again.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial