Resizing a Subform as Data is Entered

E

Eric D. Braden

I am trying to resize a subform as data is entered into it. The
subform is, in its entirety, just one combo box that multiplies for
each record. I have it set now so that if there are no appropriate
records in the table associated with the subform, it just shows a
blank record (with the asterisk) for the user to select from the combo
box.

As the user selects items, the subform should grow so that each record
is shown. I wrote this little bit of code that seems to work
reasonably well, though I haven't figured out the best event to
associate it with to be sure it runs when I want it to.

RecCount = DCount("CaseModID", "t_CaseMod", "CaseID =
Forms.f_CaseEdit.CaseID")
Me.sub_CaseMod.Height = RecCount * 300 + 300
End If

This does what I want it to, except for one thing. The first record a
user inserts disappears upward (I have the scrollbars disabled).
After that, it looks great, showing all current records, plus the
blank "add new" record and growing correctly. If I have the code in
the Current of the form it will display correctly if you move to
another record and then back. It also appears correctly if I tie it
to a button. If I add an extra dead space of 300 twips at the
beginning with an If RecCount<1 statement, it just moves the same
errant behavior the second record and maintains the extra dead space
at the bottom.

Has anyone experienced this behavior? Is this simply a matter of me
placing the code with the appropriate event? I have tried it with
dirty, before update, after update, on change, and even on mouse move
and it repeats this behavior.

Any help is greatly appreciated.

Eric B
 
E

Eric D. Braden

A revision:

I was able to get this working correctly when using the tab key to
move to the next subform record with this on the combobox in the
subform:

Private Sub ModID_LostFocus()
RecCount = DCount("CaseID", "t_CaseMod", "CaseID =
Forms.f_CaseEdit.CaseID")
Me.Parent.sub_CaseMod.Height = (RecCount + 1) * 315
End Sub

However, if the user selects from the combo box using the mouse, by
clicking on the down arrow, then clicking his selection, it doesn't
update (for obvious reasons, since it doesn't lose focus). Is there a
way to trigger the event on the action of selecting an item from the
list with the mouse? I tried Mouse Down and Mouse Up, but those seem
to prevent the user from actually being able to select anything.

Any input?
 

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