[AccessD] Sub Report Syntax...

Darryl Collins Darryl.Collins at coles.com.au
Sat Aug 9 19:18:52 CDT 2008


A big thank you to all whom responded to this, esp A.D.Tejpal who provided these insightful details.  It is Sunday morning here in Oz right now (and a damn cold and wet sunday morning too).  Not sure if I will look at this later today or not, but once I get this fixed I will post back for the archives.

many thanks to all.

warm regards
darryl.



-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of A.D.Tejpal
Sent: Saturday, 9 August 2008 11:52 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Sub Report Syntax...


Label captions in subreport - dynamic assignment
=================================

Darryl,

    In case of reports, time flow has to be kept in view. Open event of subreport fires later than that for the parent report. Run time assignment of label captions (or values for other controls) in a report has to be carried out in events belonging to THAT report.

    This implies that in case of a subreport, you have to use an event of the report serving as source object for the subreport control in question. Any attempt to do so, directly in open event of the parent report itself leads to error 2455 (Invalid reference to property - Form/Report). This is because, at the open event stage of parent report, various controls (including the subreport control) are still in a state of flux, and do not yet expose the full range of their properties. Moreover, at this juncture, even the open event of subreport itself is yet to fire (the subreport is thus not yet effectively available at this stage).

    Following alternatives can be considered for run time assignment of label captions in a subreport. The term subreport represents the report used as source object for the subreport control. LbBudget is the name of label on subreport's report header:

    1 -  Use value held by a form control:
    -------------------------------------
    This method for assigning caption for subreport's label is simplest and straightforward. Sample code in subreport's open event is given below :

' Code in subreport's module
'=======================================
Private Sub Report_Open(Cancel As Integer)
    Me.LbBudget.Caption = _
                    Forms("F_Report")("TxtCaption")


    ' Note - TxtCaption is the name of text box
    '             on form F_Report, holding the desired
    '             caption string (Form F_Report should
    '             be in open state).
End Sub
'=======================================

    2 - Pass OpenArgs value to main report:
    -----------------------------------------
    Assign the caption string for subreport's label as per value of OpenArgs passed on to the parent report. This method too is simple and straightforward, but available only in versions later than Access 2000. Sample code in command button's click event and subreport's open event is given below :

' Code in form's module
' (CmdReport is the name of command button)
'=======================================
Private Sub CmdReport_Click()
    DoCmd.OpenReport "R_Main", _
                    acViewPreview, , , , "<<MyCaptionString>>"
    DoCmd.Maximize
    DoCmd.RunCommand acCmdZoom100

    ' Note - R_Main is the name of parent report.
End Sub
'=======================================

' Code in subreport's module
'=======================================
Private Sub Report_Open(Cancel As Integer)
    Me.LbBudget.Caption = Me.Parent.OpenArgs
End Sub
'=======================================

    3 - Use a caption string generated in
          parent report's open event:
          ---------------------------------
    Assign the caption on subreport's label as per a string explicitly declared in parent report's open event. This method uses report level public global variable in the parent report. Normally, either of alternatives 1 or 2 mentioned earlier should suffice. Use of parent report's open event for determining subreport label's caption could be considered only if the intended string is going to depend upon code in parent report's module. Sample code in parent and subreport's modules is given below :

' Code in parent report's module
'=======================================
' Declarations section
Public CapString As String

-----------------------------------------------------------
Private Sub Report_Open(Cancel As Integer)
    CapString = "<<MyCaptionString>>"
End Sub
'=======================================

' Code in subreport's module
'=======================================
Private Sub Report_Open(Cancel As Integer)
    Me.LbBudget.Caption = Me.Parent.CapString
End Sub
'=======================================

    Important:
    ----------
    In a parallel situation, if values to subreport's text boxes were to be assigned at run time (as compared to label captions), subreport's open event would no longer be suitable. Any attempt to do so would trigger error -2147352567 (80020009) "You can't assign a value to this object." Appropriate section event subsequent to report's open event (e.g. report header's format event) can be used for this purpose.

    You might like to adopt the alternative considered most convenient for your situation.

Best wishes,
A.D.Tejpal
------------

  ----- Original Message -----
  From: Darryl Collins
  To: 'Access Developers discussion and problem solving'
  Sent: Friday, August 08, 2008 12:00
  Subject: [AccessD] Sub Report Syntax...


  Hi all,

  A dead easy one I am sure, but got a bad case of fried brain this friday afternoon.  What is up with this syntax...

  [Reports]![rpt_ProjectSummary].[rpt_TL1].[Report].Budget.Caption = sBudget

  is returning "Invalide Ref to Property Form/Report", which would suggest a spelling or naming error, but I check that about 20 times already.  Or do have the syntax all buggered for the subreport.

  I want to write the value of the string "sBudget" into a label (named budget) on the subreport.  Can be that hard surely!!??
  :)

  cheers
  Darryl.
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



This email and any attachments may contain privileged and confidential information
and are intended for the named addressee only. If you have received this e-mail in
error, please notify the sender and delete this e-mail immediately. Any
confidentiality, privilege or copyright is not waived or lost because this e-mail
has been sent to you in error. It is your responsibility to check this e-mail and
any attachments for viruses.  No warranty is made that this material is free from
computer virus or any other defect or error.  Any loss/damage incurred by using this
material is not the sender's responsibility.  The sender's entire liability will be
limited to resupplying the material.





More information about the AccessD mailing list