Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Oct 2004
    Location
    Minnesota, USA
    Posts
    151
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing Report Control Source at Run Time (2003)

    I have a report format that I want to use for five things. All fields are the same except for one. If the user picks the management report, I want the comments in a memo field to be management comments. If they pick confidential, the confidential comments should show on the reports. Only the comments change depending on the report type the user would select (the basic account information would stay the same).

    The record source for the report is a "master" query I use for several reports.

    Is there a way to tell the report if X option is selected on a selection form, that the data source for the Comment control = Field X, or if the user selects option Y, the data source would be Field Y, etc? The fields are in the master query.

    I hope this makes sense. Thanks for your suggestions.

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

    Re: Changing Report Control Source at Run Time (2003)

    Put an option group grpOption on the selection form, with radio buttons for each of the five options. Use this to pass the name of the appropriate field in the OpenArgs argument of DoCmd.OpenReport:

    Private Sub cmdReport_Click()
    Dim strField As String
    Select Case grpOption
    Case 1
    strField = "memManagementComments"
    Case 2
    strField = "memConfidentialComments"
    ...
    End Select
    DoCmd.OpenReport ReportName:="rptAccounting", View:=acViewPreview, OpenArgs:=strField
    End Sub

    In the On Open event of the reoprt, set the Control Source of the text box that will display the comments:

    Private Sub Report_Open()
    If Not IsNull(Me.OpenArgs) Then
    Me.txtComment.ControlSource = Me.OpenArgs
    End If
    End Sub

  3. #3
    2 Star Lounger
    Join Date
    Oct 2004
    Location
    Minnesota, USA
    Posts
    151
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Changing Report Control Source at Run Time (2003)

    Thanks, Hans.

    Works great.

Posting Permissions

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