MoveSize not working as expected

D

Dale Fye

I'm trying to open a form directly over the top of another form. I'm doing
this using the following code in the forms Load event:

If IsLoaded("frm_LD_Comments") Then
Set frm = Forms("frm_ld_Comments")
DoCmd.MoveSize frm.WindowLeft, frm.WindowTop, _
frm.WindowWidth, frm.WindowHeight
Set frm = Nothing
End If

What I was expecting is that the new form would open, and then reposition
over the top of frm_LD_Comments. but it is actually getting positioned about
1" higher and 1/2" to the left of frm_LD_Comments. Any ideas what is causing
this?

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
J

John Spencer

Which form is the active form at this point?

You may need to wait until after the form is loaded for it to be the active form.

AS a test try moving the code to the Current Event of the form. If that works
then you can dim a static variable in the event and check to see if it has
been set or not.

Static iCount as Long

If iCount = 0 then
iCount = 1
'do your movesize stuff here
End if


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
D

Dirk Goldgar

Dale Fye said:
I'm trying to open a form directly over the top of another form. I'm
doing
this using the following code in the forms Load event:

If IsLoaded("frm_LD_Comments") Then
Set frm = Forms("frm_ld_Comments")
DoCmd.MoveSize frm.WindowLeft, frm.WindowTop, _
frm.WindowWidth, frm.WindowHeight
Set frm = Nothing
End If

What I was expecting is that the new form would open, and then reposition
over the top of frm_LD_Comments. but it is actually getting positioned
about
1" higher and 1/2" to the left of frm_LD_Comments. Any ideas what is
causing
this?

Is this form (the one you're opening, with the code above) a PopUp form, by
any chance? Or opened in dialog mode? In such cases, the form's parent is
the desktop (I think), and so the coordinates are all off.
 
D

Dale Fye

John,

I stuck a line (msgbox screen.activeform.name ) inside the IF/End If and it
indicates that the active form is frm_LD_Comments_Add, which is the form I'm
trying to reposition.

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
D

Dale Fye

Dirk,

Yes, it is being opened in acDialog mode.

It's not a big deal to add a couple of offsets, I was just wondering whether
anyone knew why this was occuring.

I would normally just hide the form that I'm attempting to overlap, but it
was opened in dialog mode as well, and hiding it would allow the code (which
follows the OpenForm method on the main form) to continue processing.

Thanks for the info.
--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
D

Dirk Goldgar

Dale Fye said:
Dirk,

Yes, it is being opened in acDialog mode.

It's not a big deal to add a couple of offsets, I was just wondering
whether
anyone knew why this was occuring.

I would normally just hide the form that I'm attempting to overlap, but it
was opened in dialog mode as well, and hiding it would allow the code
(which
follows the OpenForm method on the main form) to continue processing.


You may be able to use Nicole Calinoiu's FormWindow class to control this:

http://www.mvps.org/access/forms/frm0042.htm
Forms: Move and Resize form windows from code

I'm not sure, but I wouldn't be at all surprised. I believe that class uses
API calls to get the parent window's coordinates.
 
P

Paul Shapiro

I just wrote some code for a similar situation. The code runs in the form
which is initially open when the user double-clicks an item in a listbox. It
opens frmParticipant to show the details of that item. The newly-opened form
is moved to the top left corner of the Access window. I turn off the modal
property on the originally open form so the user can work with the new form.
Finally I move the original form to the bottom of the new form so the new
form is almost completely visible.

DoCmd.OpenForm FormName:=strForm
Set frmParticipant = Forms(strForm)
frmParticipant.Move Left:=0, Top:=0
Call frmParticipant.GoToRecord(lngParticipantID:=lngActorID,
lngEventID:=lngEventID)

'Allow the user to click on the newly-opened form
Me.Modal = False
'Me.MinMaxButtons = 1 'Show the minimize button (ONLY available in
design mode)
'Me.PopUp = False 'Can only be set in design mode.
'frmParticipant.SetFocus 'User might not know this (partly-covered) form
has focus

'Move this form out of the way
Me.Move Left:=Me.WindowLeft, Top:=frmParticipant.WindowTop +
frmParticipant.WindowHeight
 

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