Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Dec 2006
    Posts
    250
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Printing from a subform (2003)

    Hello, I have a subform that has a filter on it. I want to print just the information on that subform with the corporations name on it. How can I go about doing this? When I use the code below I get every not there is

    Private Sub Command123_Click()
    On Error GoTo Err_Command123_Click

    Dim stDocName As String

    stDocName = "RTPQryNotes"
    DoCmd.OpenReport stDocName, acNormal

    Exit_Command123_Click:
    Exit Sub

    Err_Command123_Click:
    MsgBox Err.Description
    Resume Exit_Command123_Click

    End Sub

    Any help would be great. Thanks.

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

    Re: Printing from a subform (2003)

    Where is the command button Command123? On the main form or on the subform?

  3. #3
    3 Star Lounger
    Join Date
    Dec 2006
    Posts
    250
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing from a subform (2003)

    I currently have it in the tab where the subform recides. Should I put it on the subform itself or on the tab?

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

    Re: Printing from a subform (2003)

    No, you can leave it where it is; I just needed to know where you placed it.

    Let's say the name of the subform as a control on the main form is frmSubform, and that it is linked to the main form by a number field named ID. You can change the code as follows:
    <code>
    Private Sub Command123_Click()
    On Error GoTo Err_Command123_Click

    Dim stDocName As String
    Dim stWhereCondition As String

    stDocName = "RTPQryNotes"
    ' The condition that links the subform to the current record in the main form
    stWhereCondition = "ID = " & Me.ID
    With Me.frmSubform.Form
    ' If the subform is filtered, then ...
    If .FilterOn = True And Not .Filter = "" Then
    ' ... add the filter of the subform
    stWhereCondition = stWhereCondition & " AND " & .Filter
    End If
    End With

    ' Open the report with the where-condition
    DoCmd.OpenReport stDocName, acNormal, , stWhereCondition

    Exit_Command123_Click:
    Exit Sub

    Err_Command123_Click:
    MsgBox Err.Description
    Resume Exit_Command123_Click
    End Sub</code>

Posting Permissions

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