Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2004
    Posts
    11

    Unanswered: Modify Report Field from Module

    Ok, here's the short version: I want to change the value of an unbound text box on a Report from a function in a Module.

    Here's the long version: I have a form that accepts input from the user including a range of dates and then passes this information to a function in a seperate module. The function creates a select query using the information passed from the form. Then the function opens a report with the query as its record source. What I'm trying to do is have a text box at the top of the report that has the date range they entered on the form.

    Here is the code I'm using now:

    DoCmd.OpenReport "rptProdWeek", acViewPreview

    strWeekOf = datStart & " through " & datEnd
    Reports!rptProdWeek!txtWeekOf = strWeekOf

    This doesn't cause an error but the text box txtWeekOf doesn't change. What am I doing wrong?

  2. #2
    Join Date
    Sep 2004
    Location
    Reston, VA
    Posts
    86
    You'll have to open the report in design view first in order to assign a value to control in a report. A report opened in preview mode has already printed. Once in design view, assign the value through the ControlSource of the textbox, making sure to precede the value with an "=".

    Make sure your textbox is unbound and try this instead:

    Code:
    strWeekOf = datStart & " through " & datEnd
    DoCmd.OpenReport "rptProdWeek", acViewDesign
    Reports!rptProdWeek!txtWeekOf.ControlSource = "=" & strWeekOf
    DoCmd.OpenReport "rptProdWeek", acViewPreview
    You may also want to think about filling your textbox through the Report_Open event of the report.

    Hope this helps.

  3. #3
    Join Date
    Dec 2004
    Posts
    11
    Thanks that worked great! I just had to add DoCmd.Close acReport, "rptProdWeek", acSaveYes before reopening the report in preview so that the user wouldn't get a save changes dialog when they closed the report.

    I guess I could use the Report_Open event. I would have to have a couple global variables, though.

    Anyway, it's working now. Thanks again.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Glad you got a fix, that provides a solution. I'm not being confrontational but:-

    Quote Originally Posted by jrmywvr
    I guess I could use the Report_Open event. I would have to have a couple global variables, though.
    Not neccesarily true, you could put near identical code in the report open event and set the reports caption property
    eg

    me.caption="This report covers the period " & forms!frmcallingform!startdate & " to "& forms!frmcallingform!enddate

    on any other variationon the theme.

    The main downside is that it means you have to call the report from that calling form -its marginally more limiting. You could trap the error and spot you were in development mode but each to thier own I say

Posting Permissions

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