Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print data from Filter by Form (2003)

    I have a form that I am using filter by form. Is there a way to print the filtered data? I found the following code but not sure how to use it or if it is appropriate for what I want to do.
    Sub FilteredReport()
    Dim strFilter As String
    If Me.Dirty Then
    RunCommand acCmdSaveRecord
    End If
    If Me.FilterOn Then
    strFilter = Me.Filter
    End If
    DoCmd.OpenReport "rptEmployees", acViewPreview, , strFilter
    End Sub
    This assumes that the code is in the form's module. Also, I am not sure about where to put the code. What is meant by "code is in the form's module"?

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

    Re: Print data from Filter by Form (2003)

    The code you found (in <post:=613,363>post 613,363</post:>?)assumes that you have created a report (rptEmployees in the example) based on the same record source as the table.
    The procedure (sub) FilteredReport can be called from the On Click event procedure of a command button on the form. FilteredReport should be in the same module as the On Click event procedure, i.e. in the code module that belongs to the form.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print data from Filter by Form (2003)

    How do I call the Sub FilteredReport. What is the code behind the command button to do this?

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

    Re: Print data from Filter by Form (2003)

    Open the form in design view.
    If you haven't created the command button yet, do it now (from the Control Toolbox).
    Click on the command button to select it.
    Activate the Properties window (select View | Properties if necessary).
    Activate the Format tab of the Properties window.
    Specify an appropriate caption for the button, for example Print Data
    Activate the Other tab of the Properties window.
    Specify a meaningful name for the button, for example cmdPrint
    Activate the Event tab of the Properties window.
    Find the On Click box and click in it.
    Select [Event Procedure] from the dropdown list in this box.
    Click the button with the three dots ... to the right of the dropdown arrow.
    This will create the "skeleton" for the event procedure. It looks like this:
    <code>
    Private Sub cmdPrint_Click()

    End Sub
    </code>
    The insertion point will be in the empty line between Sub ... and End Sub.
    Press the Tab key once, then type or copy/paste the following line:
    <code>
    Call FilteredReport
    </code>
    You should see something like this:
    <code>
    Private Sub cmdPrint_Click()
    Call FilteredReport
    End Sub
    </code>
    If you haven't done so yet, copy the FilteredReport procedure into this module, for example at the end (bottom) of the module.
    You can now switch back to Access, save and close the form, then reopen it to test it.

Posting Permissions

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