Results 1 to 7 of 7
  1. #1
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Variable Report Title (Access 2002)

    In a report is there a way to set the text property of a text box to the result of a code calculation made when the report opens?

    I have code that runs when the form opens and it establishes a string variable (stTitle) based on parameters in the form that calls the report.
    I would then like to equate the text property of the text box containing the report title to this string, i.e. txtTitle.text = stTitle. However, I get an error message stating that I can't do this unless the text box has focus. But I get another error when I insert code that attempts to set the focus on the text box.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Variable Report Title (Access 2002)

    You should be able to use a text box on the report with an expression as control source that includes the parameters from the form. For example:

    ="Sales data for the period from " & [Forms]![frmInput]![txtStartDate] & " through " & [Forms]![frmInput]![txtEndDate]

    No code needed for this.

  3. #3
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Variable Report Title (Access 2002)

    Hi Hans,

    My you are prompt! However, the way I build the title string is somewhat complicated. I've decided to try generating the title string using code in the calling routine and then pass the result to the text box in the report.

    Thanks as usual.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Variable Report Title (Access 2002)

    When you do so, just use txtTitle = strTitle, don't use the .Text property, and don't try to set focus to txtTitle - you can't set focus to controls on a report.

  5. #5
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Variable Report Title (Access 2002)

    Well, I guess I have a lot to learn about passing arguments. I've been trying the OpenArgs method with this statement in the calling routine frmMainMenu:

    DoCmd.OpenReport strDocName, acPreview, , , , "Title Here"

    where "Title Here" is in the OpenArgs segment of the DoCmd line.

    And this code in the Open event of the report:

    Dim strTitle As String
    strTitle = Forms!frmMainMenu.OpenArgs

    But when I call the report I get an "Invalid use of null" message in the "strTitle = Forms!frmMainMenu.OpenArgs" line.

    The above code segments seem to match those in the OpenArgs help file, but it's obviously not working.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Variable Report Title (Access 2002)

    You pass OpenArgs to the report, so you should not refer to the OpenArgs of the calling form, but to the OpenArgs of the report itself:

    strTitle = Me.OpenArgs

  7. #7
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Variable Report Title (Access 2002)

    Ooooh how simple. I just entered "=OpenArgs" in the text box and it works.

    Thanks again Hans.

Posting Permissions

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