[AccessD] Subform Errors

Gustav Brock gustav at cactus.dk
Sun Jun 22 02:12:18 CDT 2003


Hi Doug

> I have an Access 97 database and am having a problem with a
> form/subform.  The main form holds data for the parent record and the
> subform shows data for the child records for the parent; a typical
> design.  The subform is based on a semi complex query that has some
> calculations in it that sum some cost fields for each record.  There are
> several hidden calculated text boxes on the subform that perform further
> data aggregations for several fields from each record.  I refer to these
> fields in controls on the parent form to show their value.  Hopefully
> this description isn't too confusing.

> The problem is that the forms work correctly when the main form is first
> opened in design view and then switched to form view.  When the form is
> opened in this fashion and a record selected from a selector combo box
> all fields function and calculate correctly.  If the main form is opened
> directly to form view and a record selected the calculated controls
> contain "error". If I then switch the form to design view and back to
> form view it works correctly.  There is very little code behind these
> forms and nothing on a form event except docmd.maximize on form
> activate.  This is the first time I have run into this situation.  Why
> would the form behave differently based on whether it was first opened
> in design view or directly into form view?

I think Susan is on the track. And if you dig the archives, Mr. Colby
once described something about the opening of a subform - that it
happens twice when opening a form with a subform.

Once I had a similar problem but that was a speed issue; the controls
on the parent were recalced too slow. A "manual" recalculation in the
Current event of the parent form solved it.

Here's a snip:

  curSumLine = 0
  curSumUsed = 0
  '
  Set rst = frmSub.RecordsetClone
  With rst
    If .RecordCount > 0 Then
      .MoveFirst
      Do Until .EOF
        curSumLine = curSumLine + (!Sold * !Cost)
        curSumUsed = curSumUsed + !Used
        .MoveNext
      Loop
    End If
    .Close
  End With
  '
  Me!txtSumLine = curSumLine
  Me!txtSumUsed = curSumUsed

However, if you update the records of the subform you'll have to have
similar code in the subform to recalc the textboxes on the parent
form. 

/gustav



More information about the AccessD mailing list