Re-centre a form?

J_Orrell

Registered User.
Local time
Today, 09:34
Joined
May 17, 2004
Messages
55
Guys, sorry it's a along time since I posted, and I only ever seem to post queries.

The short tale is that I've written VBA code that hides or shows certain fields on a form depending on whether the user ticks a checkbox in the form's header. I've already written code that shuffles the columns and controls around so there isn't a gaping hole where the hidden fields are, and I've used 'DoCmd.RunCommand acCmdSizeToFitForm' to resize my form. It all works fine.

What I can't find is simple concise code to re-centre the form in its smaller size. The 'Autocenter' property of the form is already set to True, it seems bizarre there is no way to re-trigger it, or force the form to re-draw (and hence re-trigger it).

Any ideas? Thank you.
 
What you can do is save the size of the form when it opens, then save the size of the form after your resize. Then, subtract, divide by 2, and that's how much you move the form. Here's some simple concise code . . .

Code:
dim xMove as long
xMove = (xOnOpen - xAfterResize) / 2
Me.Move me.WindowLeft + xMove

Hope this gets you started,
 
Thanks Mark that looks straightforward, I'll give that a go.
 
Knew that looked too easy to be true...the 15 year old version of MS Access I am confined to using with my employer appears not to have .WindowLeft, so I fell at the first hurdle of getting the start position. There's no doubt an API I can call, like I had to do to circumvent the fact the useless outdated piece of rubbish doesn't have .FileDialog either. Probably more trouble than it's worth in the circumstances.
 

Users who are viewing this thread

Back
Top Bottom