Form position on screen

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I need a specific form to position itself on the screen in relation to
another opened form.

In other words, I open frmForm2 from a command button on frmForm1. frmForm1
stays open and frmForm2 sets itself on top of frmForm1 but with an offset to
the bottom and to the right.

Anyone of you has a clue how can I manage to do this with VBA?

Thanks a bunch in advance!
 
You should be able to use something like the following in the Load event of
frmForm2:

Me.Top = Forms!frmForm1.Top + 500
Me.Left = Forms!frmForm1.Left + 500

The "trick", of course, is that this will fail if frmForm1 isn't actually
open. You can trap the error 2450 that will occur when that's the case.
 
It's not working.
..Top and .Left does not seem to be a property of the Form object.

Any other idea?
 
That's what I get for not checking my facts before posting. Sorry about
that...

You can use the MoveSize method to reposition the form, but I'm not sure how
you determine what you're moving it relative to.
 
Alright... This works good. It seems to be relative to the left and top
corner of the screen.

Thanks Douglas!
 
Gaetan said:
Alright... This works good. It seems to be relative to the left and top
corner of the screen.

Thanks Douglas!

If you need previous Form position you can use GetClientRect(if Form was not
POPUP)...
and convert Rect(Top/Left) in Twips to use on MoveSize, or in pixels to use
on Move(Api)
 
Back
Top