using of "parent" in a report in order to omit superflous reports

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BeckerHarald
    New Member
    • May 2015
    • 5

    using of "parent" in a report in order to omit superflous reports

    I have 2 forms. In each of them I call a different report.
    Code:
    DoCmd.OpenReport "481rpt_KursteilnehmerQuittungDrucken", _
       acPreview
    DoCmd.OpenReport "483rpt_TermineQuittungDrucken", _
        acPreview
    Inside the reports the datasource is referenced with
    Code:
       =[Formulare]![481frm_KursTeilnehmerErfassen]![KLNachname]
    or
       =[Formulare]![483frm_TerminsErfassen]![KLNachname]
    Don't get troubled: Formulare is German and means forms!!

    As you easily see, they are very similar. I tried to use the same fieldnames in both of the forms.
    I have the strong feeling, that ONE report could be omitted.
    So I looked for a reference like
    Code:
        =[Formulare]!me.form![KLNachname]
    or
        =[Formulare]!parent.form![KLNachname]
    It is a shame - I was not successful. Can you help me?
    Thank you all
    Last edited by zmbd; May 11 '15, 04:15 PM. Reason: [z{placed code tags, please refer to FAQ}{corrected a typo or two :) }]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    You've only provided names of reports and examples of functions; however, you've really provided no information about the reports/forms themselves nor the structure pertaining to the scope of the calling code.

    TBH: The inclusion or omission of a report is really something that is decided by your client and not something that many of use would be able to help you decide. A specific question about how to include/exclude something, formatting, even occasionally a suggestion on how to design a project (especially when it comes to normalization ) that we can be of more help with...
    Last edited by zmbd; May 11 '15, 04:22 PM.

    Comment

    • BeckerHarald
      New Member
      • May 2015
      • 5

      #3
      zmbd, thank you. I should add: it is ACCESS 2013

      I tried to be short as it was recommended. There is no VBA-Code. Just a reference in a field in the report to a field in a forms which must be opened (otherwise the reference will not work).

      The reference for the field
      Code:
      =[Formulare]![481frm_KursTeilnehmerErfassen]![KLNachname]
      is given as datasource (German: Steuerelementin halt).

      The name of the form "481frm_K.. .." is static. If I use a dynamic term to reference a form in a field of a report (e.g. "me" or "parent") I hope to be more elegant.

      The simple?? question is: how looks an example of a reference inside a field of a report to a field of a form using me or parent?

      [I was sure that in this community we all talk about access therefore I did not give this information]
      Last edited by zmbd; May 11 '15, 06:00 PM. Reason: [z{Placed BH's comment in post}{Placed Code Tags around formula as required}]

      Comment

      • jforbes
        Recognized Expert Top Contributor
        • Aug 2014
        • 1107

        #4
        There are a few ways to do what you are attempting. For you, I would look into TempVars first, then possibly OpenArgs.

        Here is a thread that is similar in nature: http://bytes.com/topic/access/answer...cked-main-form
        Syntax of using a TempVar as the Source for a Report Control: http://bytes.com/topic/access/answer...command-button

        Comment

        • BeckerHarald
          New Member
          • May 2015
          • 5

          #5
          Thank you, jforbes

          openargs was my first idea. As far as I understood, with openargs I can pass only ONE argument from the form to the report. Actually there are 8 variables to pass.

          But you gave me the following idea: If it is not possible to give more than ONE argument, than I will gather the 8 variables into ONE argument, in which these 8 variables are separated by e.g. @. Then I will divide this ONE argument inside the report into 8 variables. I will do this with VBA-Code. This is not as elegant as my introducing question concerning "parent", but ...

          Again: Thank you

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            BeckerHarald, from the information you've given, I'd point you in the same direction as jforbes.

            As for this being an Access forum, you are correct, and we do appreciate you being brief and to the point; however, Access is a very fluid development environment and when one posts just snippets of code/script one must provide proper context.

            For example in your original post:
            ... Inside the reports the datasource is referenced with ...
            isn't clear in that the report can have a record source and the control can have a control source, which one might lump together and call "datasource " even if not technically correct, and the explanation you have provided, along with your title, leads one to wonder if you are using a parent/subreport format and just exactly how is it that the form is related to the report that would possibly allow Me/Parent scope between the report and the form?

            AND NOW

            You have provided us with even more information regarding the multiple parameters you wish to pass to the report.

            I have a link for that and will update this post in a minute once I find and verify it still works:
            <<update>>I see that you have the same idea as the link, personally, I use the split function and the pipe character ( | ) as the "@" can occasionally give you problems. You might want to look at the underlying query to see if a parameters based approach would work.

            Also, you clearly state that there is no VBA code and yet, DoCmd.OpenRepor t is a VBA function so there is VBA code being used in your project.
            Last edited by zmbd; May 11 '15, 06:36 PM.

            Comment

            • jforbes
              Recognized Expert Top Contributor
              • Aug 2014
              • 1107

              #7
              There is one more thing that you could consider. Sending the Form Name as the OpenArgs. I use this technique for Forms, but it would work with Reports quite well.

              I mocked this up from some code I had and with what you provided. It is still Form based, so you'll have to shoehorn it into a Report, if you want.
              Code:
              Private Sub Form_Load()
                  ' Put the Parent in a hidden field
                  Me.ParentForm.Value = Nz(Me.OpenArgs, "")
              End Sub
              Private Sub cmdOK_Click()
                  Dim sParent As String
                  sParent = Nz(Me.ParentForm.Value, "")
                  If isLoaded(sParent) Then
                      Select Case sParent
                          Case "481frm_KursTeilnehmerErfassen"
                              Me.KLNachname=[Formulare]![481frm_KursTeilnehmerErfassen]![KLNachname]
                          Case "483frm_TerminsErfassen"
                              Me.KLNachname=[Formulare]![483frm_TerminsErfassen]![KLNachname]
                      End Select
                  End If
              End Sub
              Function isLoaded(ByRef sFormName As String) As Boolean
                  ' Determines if a Form is loaded
                  Dim i As Integer
              
                  isLoaded = False
                  For i = 0 To Forms.Count - 1
                      If Forms(i).FormName = sFormName Then
                          isLoaded = True
                          Exit Function
                      End If
                  Next
              End Function
              Also, there are a few other ways to refer to an open form and the syntax like the following may simply things for you:
              Code:
              Forms("481frm_KursTeilnehmerErfassen")![KLNachname]

              Comment

              • zmbd
                Recognized Expert Moderator Expert
                • Mar 2012
                • 5501

                #8
                J, that's pretty slick, sending the form name in the openargs, I wouldn't have thought to do that, I normally put a parameter query together using a form to fetch user input.

                I wonder if there isn't something that we're missing here as to the overall database design that could make the project easier for OP.

                Comment

                • BeckerHarald
                  New Member
                  • May 2015
                  • 5

                  #9
                  To zmbd and jforbes!

                  zmbd, now after you showed me, what you mean when you ask me to give more information I am a little angry - with me!
                  I am/was too deep involved into my problem that a structured thinking was impossible.

                  jforbes, although I got no answer if there is a valid syntax (or example) for a reference from the control source?? of a report field to a field in a form, my problem is solved!

                  I tried to omit superflous reports while using "me or parent". Now I am able to omit these reports. Instead I will have only ONE report left for this given situation while using openargs.

                  Thank you ALL. I really appriciate the fast way you tried to help.

                  And good night - it is bed time in Germany!

                  Comment

                  • zmbd
                    Recognized Expert Moderator Expert
                    • Mar 2012
                    • 5501

                    #10
                    I am/was too deep involved into my problem that a structured thinking was impossible.
                    If I had a dollar/EUR/DEM for every tree I've ran into because of the forest I'd fly over and we go for a beer.

                    :-)

                    Comment

                    • jforbes
                      Recognized Expert Top Contributor
                      • Aug 2014
                      • 1107

                      #11
                      Glad to hear that you got things working for you.

                      I took it as a challenge to find a way to define a Control Source that would pull the value from a "Parent" Form and here is what I came up with.

                      For the Form calling the Report, pass the Form Name as an OpenArg:
                      Code:
                      Private Sub Command0_Click()
                          DoCmd.OpenReport "rptReportWithOpenArgs", acViewPreview, , , , Me.Name
                      End Sub
                      Then in the Report on Load Event put the OpenArg in a Report Variable. This will make the Calling Form Name available for a Function that would retrieve the value from the calling Form. Code from the Report
                      Code:
                      Option Compare Database
                      Option Explicit
                      Private nFormName
                      Private Sub Report_Load()
                          nFormName = Nz(Me.OpenArgs, "")
                      End Sub
                      Private Function getParentValue(ByRef sValue As String) As String
                      On Error GoTo ErrorOut
                          If Len(nFormName) > 0 Then getParentValue = Forms(nFormName).Controls(sValue)
                      ExitOut:
                          Exit Function
                      ErrorOut:
                          MsgBox ("Error in rptReportWiothOpenArgs.getParentValue. Form Name of '" & nFormName & "' Value of '" & sValue & "' " & vbCrLf & vbCrLf & Err.Description)
                          Resume ExitOut
                      End Function
                      Then on the Report if a Controls Source is set like this:
                      Code:
                      =getParentValue("txtReportTitle")
                      the value that is shown on the report will be the Value of the Control named "txtReportTitle " on the "Parent" Form.

                      I think there is more that could be done, but I need to get back to work. =)
                      Last edited by jforbes; May 12 '15, 12:47 PM. Reason: typo

                      Comment

                      • BeckerHarald
                        New Member
                        • May 2015
                        • 5

                        #12
                        Hi jforbes,
                        after you mentioned to pass the name of the form into the report I immediately forgot to sample the 8 variables in the form, pass them as ONE openargs and split them in the report.
                        Both, my (old) solution and your (new) solution above need VBA but yours only as load-event. Means, yours is more elegant, means subsequently I will use it as shown by you.

                        And by this way I learned the possibility to use a function in the Controls Source! You made my day! Thank you!

                        Comment

                        Working...