Positioning a small form 'on top of ' Main form ?

liamfitz

Registered User.
Local time
Today, 15:59
Joined
May 17, 2012
Messages
240
I have a very small form, which when it opens, I'd like to position precisely in relation to the main form. Is there some way of using properties, or VBA, to set screen coordinates or the like, to do so ? Thanks.
 
Yes, you can. If the main form opens, then you open the small form, in the small form's On Open you can use

Code:
Me.Top = Forms!MainFormNameHere.Top -200
Me.Left = Forms!MainFormNameHere.Left -200

Adjust the number of TWIPS as needed. I used 200 and minus to put it above and to the left of the form and you would use a positive number to move to the right and/or down.
 
You're just too good, Bob ! Many thanks again.
;)
 
I forgot to mention that you can use similar code from the main form's ON RESIZE event where you can refer to the small form:

Code:
Private Sub Form_Resize()
If CurrentProject.AllForms("SmallFormNameHere").IsLoaded Then
   Forms!SmallFormNameHere.Top = Me.Top - 200
   Forms!SmallFormNameHere.Left = Me.Left - 200
End If
And that way whenever you move the main form, the small form will come along for the ride. I used the IsLoaded part to make sure there is no error in case the small form is not open.
 
Your Me.Top = etc. ( and presumably ) Me.Left = etc., produce an error 'Method or Data member not found'. I did wonder when after typing Me. - Intellisense didn't offer these as options ?
 
Alright, Bob just forgot that form's don't have Top and Left. You can try WindowTop and WindowLeft.

Or you could use the Move method of the form or use DoCmd.MoveSize. You may need to delay it with a Timer if it doesn't work on open.
 

Users who are viewing this thread

Back
Top Bottom