Microsoft Access - Calculated fields in sub report do not show in main report

Asked By Karen Behling on 03-Jul-12 08:46 AM
I have a forcast report that contains a sub report.   The sub report has twelve calculate that data based on a query.    The query retrieves  value from a table and then via code the value is placed in the appropiate text box.

currently the code resides in the subreports "on load" event - works fine when I open the subreport by itself

Private Sub Report_load()
Dim sql1, sqmend, sqmonth As String
Dim JanHr As Long

Dim arrTotMonth(12)
Dim mymonth As Integer

Dim dbs As Database
Dim RS As DAO.Recordset
Dim rsq As DAO.Recordset
   
    Set dbs = CurrentDb
 
   
 sql1 = "SELECT [tblMonthly ForcastPrintTotals].[fPrintTot] FROM [tblMonthly ForcastPrintTotals]WHERE ((([tblMonthly ForcastPrintTotals].Fmonth)='"
 
 sqmend = "'));"

    For mymonth = 1 To 12
      'Get the Hours per project
   
   
      Set RS = dbs.OpenRecordset(sql1 & mymonth & sqmend)
     
      arrTotMonth(mymonth) = RS!fPrintTot
     
    Next

    'Populate Report
    txtJanTotHrs = arrTotMonth(1)
    txtFebTotHrs = arrTotMonth(2)
    txtMarTotHrs = arrTotMonth(3)
    txtAprTotHrs = arrTotMonth(4)
    txtMayTotHrs = arrTotMonth(5)
    txtJunTotHrs = arrTotMonth(6)
    txtJulTotHrs = arrTotMonth(7)
    txtAugTotHrs = arrTotMonth(8)
    txtSepTotHrs = arrTotMonth(9)
    txtOctTotHrs = arrTotMonth(10)
    txtNovTotHrs = arrTotMonth(11)
    txtDecTotHrs = arrTotMonth(12)

    'Calculate over short
    'txtOvShJan = (txtAvailHrsJan - txtJanTotHrs) / 19
 
 
    'Calculate projects per dat
   ' txtPojperDayJan = AccessTotalsJanuary / 19
  
End Sub




When I opent the main report all of the txt???totHrs controls are empty.   I need to have all of the fiels show their data.

Can some one help me?

Thanks
Karen
Pat Hartman replied to Karen Behling on 04-Jul-12 10:39 PM
Is there some reason you didn't bind the subreport to the table/query?  You wouldn't need the code at all then.  By setting the master/child links, Access will keep the main and sub reports in sync.
Karen Behling replied to Pat Hartman on 10-Jul-12 08:37 AM
The calucations in the sub report are only based on the data in the subreport.  The reason the subreports are not linked with the main report is because the main report is just a collection of report related by topic not by record.