Center form by VBA

  • Thread starter SurveyorinVA via AccessMonster.com
  • Start date
S

SurveyorinVA via AccessMonster.com

Hello All-

I have a form that acts as a splash screen, gives the title of the
application and a graphic while items load in the background. I am trying to
use the Docmd.MoveSize function to center this form in the application window.
When the application starts, this form will be the only one open for several
seconds so it will be against the gray background of the Access Window.

I thought I could use the following code, but it seems to be trying to center
the database tray.

intScreenHeight = Me.InsideHeight
intScreenWidth = Me.InsideWidth

intScreenHeightHalf = intScreenHeight / 2
intScreenWidthHalf = intScreenWidth / 2

intFormHeight = (2.291 * 1440)
intFormWidth = (5.3326 * 1440)

intFormTop = intScreenHeightHalf - (intFormHeight / 2)
intFormLeft = intScreenWidthHalf - (intFormWidth / 2)

DoCmd.MoveSize intFormLeft, intFormTop, intFormWidth, intFormHeight


Any thoughts would be great.

Thanks
Chris
 
J

Jeanette Cunningham

I thought that if a form had its Auto Center property set to Yes, it would
automatically be centred in the application window.

Jeanette Cunningham
 
Joined
Apr 23, 2021
Messages
3
Reaction score
0
This worked for me; note: 9000 was the width of my form, 10000 the height
Using these two values I did a calculation of the left position of the form (nleft)
and the top of the form (ntop), and then used them in the MoveSize function.

Dim nleft As Long
Dim ntop As Long

nleft = (Me.WindowWidth - 9000) / 2
ntop = (Me.WindowHeight - 10000) / 2

'DoCmd.MoveSize right, down, width, height
DoCmd.MoveSize nleft, ntop, 9000, 10000
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top