Centering a Form using VBA
Posted on 2007-04-06
I'm using Access 2007 and I'm attempting to address an issue with a continuous form seemingly taking whatever height it feels like when I open it (and changes on different PCs). I've found a tentative solution in VBA that works great but has a drawback - everything goes to the left.
Here's what I have in the form's Activate event:
Me.Move Left:=10, Top:=10, Height:=7500
This addresses the height issue perfectly. No matter what state I leave the window in while I'm designing, it always gets sized to 7500 twips upon Load. The bad part is, I have no way of knowing the total screen width and therfore cannot set the "Left" property above to a valid number to get it centered. I've tried all different combinations of Screen.Width, etc. including "Me.Move Left:=((Screen.Width / 2) - (Me.Width / 2))" but it just doesn't work (it doesn't move at all). Setting the form's property to Auto Center doesn't work either - this is overridden by the VBA code.