Question : Subform last record not showing on report

I have a subform PersonsTrained that is completed by users on a Main form called Training.  The subform is linked to a table called PersonsTrained.  The users enter one person per record in the subform.  The subform is linked to the Main Form with a field called TrainingRecord ID. The subform has a field in the form footer called PersonsTrained, that lists all the PersonsTrained separated by a comma.  The field updates as the Records are entered.  This all works just fine.  However, I have a button on the Main Form that runs a report which shows the Training Record wth a list of all the PersonsTrained from the PersonsTrained field in the Subform.  The subform PersonsTrained is placed on the report.  Here is the dilema.  I open the Main Form, complete the subform, and then click on the report on the Main Form.  The report shows the vba field with all the PersonsTrained separated by commas, but it leaves off the last record (last name).  If you exit the Main Form and come back and then run the report, the last name shows up.  Any ideas of how to make the last record from the subform show on the report without exiting the Main Form?

Answer : Subform last record not showing on report

Hi manndo

A new or changed record in a form (or subform) will not be saved until one of the following happens:

  1. the focus moved to another record in that form 
  2. or the form is closed 
  3. or the record is explicitly saved 

Your subform control is losing the focus when you click on the main form button, but this is not moving the subform to a different record, so none of the above events is happening.

I suggest you use the Exit event of the subform control to force a save:

Private Sub YourSubformControl_Exit(Cancel As Integer)
On Error Resume Next
With YourSubformControl.Form
 If .Dirty Then .Dirty = False
End With
End Sub

Good luck!
--
Graham

Random Solutions  
 
programming4us programming4us