Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2010
    Posts
    88

    Unanswered: Creating and customising a report in VBA

    Hello there....

    I'm trying to make an application "easy" to maintain, by anticipating changes that might need to be made in the future and automating them as much as possible.

    So, I have a bunch of nearly-identical reports which are all subreports to a big report. The change I wish to anticipate is that a new subreport, similar to but not quite the same as the others, needs to be added. I can't just create it now because I don't know the value of some key attributes yet - but somebody will when they come to push my magic buttons.

    So I get as far as:

    NewName = <constructed name for the new subreport>
    DoCmd.CopyObject , NewName, acReport, "subreportTemplate"

    ... which creates a new report, copied from the template, with the right name.

    I'd now like to "fix" a couple of the attributes of this report, say the value of a Label and a Filter string.

    How can I do this? I've been blundering about Opening the form and then trying to set properties via Forms! ... but I'm being told the form doesn't exist, even though I can see that it is in fact being created.

    Suggestions most welcome!

    CeejayDBF

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If you want to access to the properties of a Report object, you have to address this object through the Reports collection, not the Forms collection. Moreover, don't forget that a Form or Report object is only present in its generic collection (Forms for a Form object, Reports for a Report object) whent it's open. So:
    Code:
    Function HandleReport(ByVal ReportName As String)
    
        Dim rpt As Report
        
        DoCmd.OpenReport ReportName, acViewDesign
        Set rpt = Reports(ReportName)
        With rpt
            '
            ' Handle rpt properties and methods.
            '
            .Caption = "My Report"
            .AutoResize = True
        End With
        Set rpt = Nothing
        DoCmd.Close acReport, ReportName, acSavePrompt
        
    End Function
    Have a nice day!

  3. #3
    Join Date
    Mar 2010
    Posts
    88
    Ah, yes, I did mean Reports really, not Forms!

    However I've followed your example and now have it working - I think that first "set" statement is the key to what I was missing.

    Thanks again!

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •