report question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • didacticone
    Contributor
    • Oct 2008
    • 266

    report question

    i have a form that filters results based on an entry in an unbound text box, i then have a button that creates a report from those filtered results, using this code

    Code:
    Private Sub Command8_Click()
      If Me.Filter = "" Then
            MsgBox "Apply a filter to the form first."
        Else
            DoCmd.OpenReport "Id", acViewPreview, , Me.Filter
        End If
    is there a way to put a heading on the report by entering it into an unbound text box in the form. so if im making an attendance report, i would like to enter 'attendance' in an unbound text box after i do my filter and then create my report and 'attendance' would be on the top of the report... thanks!
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    For this I use a "Header/Footer" table with the name of the report as (part of) the key.
    Thus each report can have a different header/footer and by storing it the user can always see the last entered value. (easy when multiple reports with same header should be produced.)

    Idea ?

    Nic;o)

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      Add a label to your report in the report Header section, and name it lbl_ReportTitle . Format it as you would like to see the report title, and make sure its wide enough to contain what people might write as a report title.
      If your report header section is not visible, you can add it by clicking on the detail section, and then selecting Report Header/Footer.

      Now add the following code to the Reports open event

      Code:
      Private Sub Report_Open(Cancel as Integer)
        me.lbl_ReportTitle=OpenArgs & ""
      End Sub
      The "" after the OpenArgs assures that if OpenArgs is null the code wont fail.

      Add a textbox to your form, name it tb_ReportTitle.
      Modify the code line of the command button to:
      Code:
      DoCmd.OpenReport "Id", acViewPreview, , Me.Filter ,, Me.tb_ReportTitle & ""
      Another way of doing it without the textbox is to use a inputbox:
      Code:
      Dim strOpenArgs As String
      strOpenArgs=InputBox("Name Report:","Report Title","Report Title")
      DoCmd.OpenReport "Id", acViewPreview, , Me.Filter ,, strOpenArgs
      Hope it helps.

      Comment

      • didacticone
        Contributor
        • Oct 2008
        • 266

        #4
        i actually came up with this earlier...

        Code:
        Me.rpttxt = Forms!FormName!FormField
        it works well... any thoughts id be glad to hear... thanks for your answers though!

        Comment

        • nico5038
          Recognized Expert Specialist
          • Nov 2006
          • 3080

          #5
          I prefer not to refer to forms as a change of the form name or starting a report from a different form will cause "trouble".
          The mentioned "OpenArgs" is preferable for "ad-hoc" passing of data and can be used "universall y" as the table solution is "heavier" and would offer the user the advantage to have his(her) own text for a header or footer per report, thus saving you the trouble to add default texts like copyright, address info, etc..

          Nic;o)

          Comment

          • didacticone
            Contributor
            • Oct 2008
            • 266

            #6
            when i try it the way suggested, i get an error. "you cannot assign a value to this object" with the following highlighted

            me.lbl_ReportTi tle=OpenArgs & ""

            Comment

            • TheSmileyCoder
              Recognized Expert Moderator Top Contributor
              • Dec 2009
              • 2322

              #7
              My bad. Labels have a Caption not a value, so you need to include the .Caption to assign to labels.

              Code:
              Private Sub Report_Open(Cancel as Integer) 
                me.lbl_ReportTitle.Caption=OpenArgs & "" 
              End Sub

              Comment

              • didacticone
                Contributor
                • Oct 2008
                • 266

                #8
                yep there it goes... awesome! thanks for your help!

                Comment

                Working...