A way to accurately size a pop-up form (1 Viewer)

tcarnahan

Registered User.
Local time
Today, 10:28
Joined
Apr 21, 2015
Messages
19
Some time ago when I was programming in Access 2000, I used to get frustrated because I could never by sure what size a pop-up form would be and where it would appear. As a result, I used the code shown below to precisely size and position my form, then set PopUp = True; Modal = True. It did the trick and I could set the size and position using inches instead of Twips. It worked fine back then. I have needed to return to this technique, but I think Access has changed or I have forgotten the other settings because this no longer works for me. I think that maybe I have forgotten some other form settings.

Note: I realize there probably is an easier way to size and position, but this template had worked so well in the past. I am just trying to see if there is a simple explanation on why it is not working now.

Question: looking at my code (below), can anyone think of why it is not allowing me to size and position my form?


------------------------------------------------------------
In a regular module, I have the following statement:

Code:
Global Const gcint_Inches_to_Twips As Integer = 1440
At the top of the form module in the declaration area, I have the following code and I set the size and position of the form in inches:

Code:
Private Const mcsng_Form_Right_in_Inches As Single = 2.3
Private Const mcsng_Form_Down_in_Inches As Single = 1.5
Private Const mcsng_Form_Width_in_Inches As Single = 4.5
Private Const mcsng_Form_Height_in_Inches As Single = 2.5
In the Form Load event, I have the following:

Code:
Private Sub Form_Load()
    With DoCmd
        .MoveSize Right:=(mcsng_Form_Right_in_Inches * gcint_Inches_to_Twips)
        .MoveSize Down:=(mcsng_Form_Down_in_Inches * gcint_Inches_to_Twips)
        .MoveSize Width:=(mcsng_Form_Width_in_Inches * gcint_Inches_to_Twips)
        .MoveSize Height:=(mcsng_Form_Height_in_Inches * gcint_Inches_to_Twips)
        .Restore
    End With

End Sub
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 15:28
Joined
Sep 12, 2006
Messages
15,640
in the forms open event have

runcommand accmdsizetofitfom

then it opens at exactly the size of the design form.


not sure why your code isn't working. What border do you have? dialog/sizable etc?
 

tcarnahan

Registered User.
Local time
Today, 10:28
Joined
Apr 21, 2015
Messages
19
I am using a sizeable border.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 15:28
Joined
Sep 12, 2006
Messages
15,640
if the border is sizeable then

runcommand accmdsizetofitfom

should work normally. Does that give you what you want. It just doesn't always open continuous/datasheet forms to the height you might prefer.
 

tcarnahan

Registered User.
Local time
Today, 10:28
Joined
Apr 21, 2015
Messages
19
Thanks for the info, MackMan!

I checked your linked example, and if you notice, they talk about using DoCmd.MoveSize just like my example above.

Yes, I have a problem with my continuous forms not sizing correctly. The DoCmd.MoveSize used to take care of all of that. However, now it does not.

--------------------------------------
News flash: I just solved the problem
--------------------------------------
SOLUTION FOUND:

I went to the Form properties under the Format tab and selected:

Auto Size = Yes

Now it works as it used to. In my code, there is a little extra "junk" that people might object to, but it keeps the code for the Form_Load event constant so that I can just paste it in without thinking. Then it puts the form specific dimensions (Top, Left, Height, Width) at the top of the module where it can be found quickly AND it converts inches to Twips (dimension required by MoveSize) so I don't have to figure that out by trial and error. The code can easily be popped into any form without modifying anything but the dimensions at the top.

If you use this code, be sure to have the global value of Inches to Twips defined in a central location (mine is in a separate regular module scoped so it can be seen in any form. Then, if you change the dimensions at the top, be sure to compile before opening the form. Hope this helps!

Thanks to everyone for the suggestions!

Tom
 

Users who are viewing this thread

Top Bottom