moving button on form's resize event not working right

K

Keith G Hicks

I'm trying to move a command button up and down as a form is resized. Here's
my code in the form's resize event handler:

cmdPrintReport.Top = 5.1354 * 1440 + (Me.InsideHeight - 5.5 * 1440)

It works fine when I drag the form's height smaller than the designed
height. It also works fine as I size it bigger from there. But if I size it
just a touch taller (maybe 10 pixels or so) than the designed height I get
an error: "The control or subform control is too large for this location."

The button is not on a subform and I have no restrictions on the height of
the form. The button does not grow in height either. I see no reason at all
for this error to occur. I have similar code for moving the button left and
right as the width is adjusted and it works fine no matter what I size the
form to.

Any ideas?

Thanks,

Keith
 
M

Marshall Barton

Keith said:
I'm trying to move a command button up and down as a form is resized. Here's
my code in the form's resize event handler:

cmdPrintReport.Top = 5.1354 * 1440 + (Me.InsideHeight - 5.5 * 1440)

It works fine when I drag the form's height smaller than the designed
height. It also works fine as I size it bigger from there. But if I size it
just a touch taller (maybe 10 pixels or so) than the designed height I get
an error: "The control or subform control is too large for this location."

The button is not on a subform and I have no restrictions on the height of
the form. The button does not grow in height either. I see no reason at all
for this error to occur. I have similar code for moving the button left and
right as the width is adjusted and it works fine no matter what I size the
form to.


When making the form taller, you have to set InsideHeight
before setting the control's Top. When reducing the form's
InsideHeight, you have to set the control's Top first.
 
K

Keith G Hicks

I'm not sure I understand what you're telling me to do. The form's height is
beign changed by dragging the form's bottom edge up or down. I'm not setting
it programatically. The top position of the button is dependent on the
form's height. Can anyone show me how to code this so that I can correctly
move a button up and down to stay a specific distance from the bottom edge
of the form as the user manually resizes the form?

Keith

Keith said:
I'm trying to move a command button up and down as a form is resized. Here's
my code in the form's resize event handler:

cmdPrintReport.Top = 5.1354 * 1440 + (Me.InsideHeight - 5.5 * 1440)

It works fine when I drag the form's height smaller than the designed
height. It also works fine as I size it bigger from there. But if I size it
just a touch taller (maybe 10 pixels or so) than the designed height I get
an error: "The control or subform control is too large for this location."

The button is not on a subform and I have no restrictions on the height of
the form. The button does not grow in height either. I see no reason at all
for this error to occur. I have similar code for moving the button left and
right as the width is adjusted and it works fine no matter what I size the
form to.


When making the form taller, you have to set InsideHeight
before setting the control's Top. When reducing the form's
InsideHeight, you have to set the control's Top first.
 
M

Marshall Barton

I guess I misunderstood what you were doing.

Regardless, the error is probably because the detail section
is not expanding to the larger form size. If the form is
short enough the detail section gets the leftover space
after the form header and footer are displayed. If the form
gets taller, a continuous form will display more detail
records, but if it's in Single Form view the detail Height
does not change as the form grows. If that's the problem,
the solution is simply to make the detail section (a lot)
taller. You can do this in the form's Open event:
Me.Section(0).Height = 30000
Now, the form can not be dragged so big that the control's
position exceeds the detail height.

If your form has its header/footer sections, be sure to
adjust for that in your calculation.

You should also add some more code to skip repositioning the
button if its top would be negative.

My code for all this is:

lngPos = Me.InsideHeight - GAP - Me.cmdXX.Height _
- Me.Section(1).Height - Me.Section(2).Height
If lngPos > 0 Then Me.cmdXX.Top = lngPos
 

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

Similar Threads

OnResize event for Access Window? 1
Resizing the Details Section Height and Width. 1
Error On Resize 1
On Resize 4
Resize MSAccess Forms 2
Endless loop in resize event 13
form size 3
requery not working 7

Top