• Access 10 variable report titles

    Author
    Topic
    #495153

    How do I pass a variable to a report text box? Specifically, I want to pass “Event1” to a textbox in the report header. It’s silly to create a separate identical report for each query. I’ve done this before, years ago, but I can’t locate an example. I read elsewhere that it has to do with the namespace used by the report writer and that I have to use a function to make this variable title visible. Without context provided by this textbox, I have no way to identify 3 identical reports produced from different data.

    How do I do this? I’m stuck.

    Viewing 1 reply thread
    Author
    Replies
    • #1456433

      Where you start the report, probably from a DoCmd.OpenReport in a form somewhere, you have an option on the command line for an OpenArgs field.
      In the OnOpen event of the report just setup the textfield = OpenArgs

      • #1456443

        I’ll try that. It’s been a while since I worked in Access. Meantime, I found another way to do it, although I like yours better.

        The form containing the parms I need is the one calling this report, and it contains what I need. In the report header, I created a text box control, deleted its label, and set its control source to:

        =[Forms]![Trophies2]![EventName]

        Amazing how much you forget in a couple of years and how much time it takes to freshen up the knowledge.

        Thanks for the reply.

        • #1457020

          I’ll try that. It’s been a while since I worked in Access. Meantime, I found another way to do it, although I like yours better.

          Hi,

          Usually there are at least 3 ways to do the same in MS Access.

          One way is your way (a), but that assume you have form with text field with non-null value.

          There are few more:

          (b) Open report and add event OnFormat of the section where your header is. Write this code there

          LabelName.Caption = [Forms]![Trophies2]![EventName]

          (c) If there is no form or no text box to reference, or several reports will use one same title, you will need to create global variable by adding this to any (or new) VBA module in top of that module:

          Public strReportTitle As String

          Now, when you need to create a title for report, at any place of form add this code (usually in AfterUpdate event of text box or label):

          If Len(NZ(txtTextFieldName))> 0 Then
          strReportTitle = txtTextFieldName
          End If

          Now using same technique as in (b) change label caption:

          LabelName.Caption = strReportTitle

          Note that, in this case you do not need to have form open or dedicated text field on form for this, you can use strReportTitle variable for any report at any time.

          Regards,
          Branislav Mihaljev

    • #1457470

      You could also place the text in a table and retrieve it from there in the report.
      There are numerous ways to skin the cat.

    Viewing 1 reply thread
    Reply To: Access 10 variable report titles

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: