Form position on screen

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!
 
D

Douglas J. Steele

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.
 
G

Guest

It's not working.
..Top and .Left does not seem to be a property of the Form object.

Any other idea?
 
D

Douglas J. Steele

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.
 
G

Guest

Alright... This works good. It seems to be relative to the left and top
corner of the screen.

Thanks Douglas!
 
A

ALESSANDRO Baraldi

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)
 

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