Results 1 to 5 of 5
  1. #1
    Star Lounger bobdog's Avatar
    Join Date
    Jan 2001
    Posts
    83
    Thanks
    0
    Thanked 1 Time in 1 Post

    Access 10 variable report titles

    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.
    Last edited by bobdog; 2014-06-12 at 09:41.

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,537
    Thanks
    0
    Thanked 23 Times in 23 Posts
    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

  4. #3
    Star Lounger bobdog's Avatar
    Join Date
    Jan 2001
    Posts
    83
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  5. #4
    New Lounger
    Join Date
    Dec 2011
    Location
    Kikinda
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by bobdog View Post
    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

  6. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,537
    Thanks
    0
    Thanked 23 Times in 23 Posts
    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.

Posting Permissions

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