Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2013
    Posts
    2

    How do I Create a report displaying the results of a query controlled by a form

    I have a form that "determines the criteria" to be displayed from a query.
    here is the code - works just how i want it to:

    Option Compare Database
    Option Explicit
    Private Sub Command47_Click()
    Dim strWhere As String
    Dim lngLen As Long
    Const conJetDate = "\#mm\/dd\/yyyy\#"
    If Not IsNull(Me.Combo26) Then
    strWhere = strWhere & "([Responsible Operator] Like ""*" & Me.Combo26 & "*"") AND "
    End If
    If Not IsNull(Me.txtStartDate) Then
    strWhere = strWhere & "([DateInitiated] >= " & Format(Me.txtStartDate, conJetDate) & ") AND "
    End If
    If Not IsNull(Me.txtEndDate) Then
    strWhere = strWhere & "([DateInitiated] < " & Format(Me.txtEndDate, conJetDate) & ") AND "
    End If
    lngLen = Len(strWhere) - 5
    If lngLen <= 0 Then


    MsgBox "No criteria", vbInformation, "Nothing to do."
    Else
    strWhere = Left$(strWhere, lngLen)
    Me.Filter = strWhere
    Me.FilterOn = True
    End If
    End Sub

    Private Sub cmdReset_Click()
    Dim ctl As Control
    For Each ctl In Me.Section(acHeader).Controls
    Select Case ctl.ControlType
    Case acTextBox, acComboBox
    ctl.Value = Null
    Case acCheckBox
    ctl.Value = ""
    End Select
    Next
    Me.FilterOn = True
    End Sub

    Private Sub Exit_Click()
    DoCmd.Close
    End Sub

    Private Sub Review_Click()
    Dim carnum As Long
    carnum = Me.CARNumber
    DoCmd.OpenForm "CARData Form", , , "CARNumber = " & carnum
    End Sub

    Private Sub PrintPerformance_Click()
    DoCmd.OpenReport "Rpt1 Performance", acViewPreview
    End Sub

    I created a print option on the form, and would like to display the results of the records shown on that form, in a report. I created a report linked to the form via the print option, but can't get it to display the the current results of the form. The actual source for the report is the same source query as for the form. I am guessing that is not correct - How do I extract the data from the form to the report? Thanks

  2. #2
    TG_W is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2010
    Location
    Manvel, TX
    Posts
    299
    You will need a slightly altered version of that same query that ties to the form parameters. The 'Criteria' to be set for each field is [Forms]![YourFormNameHere]![YourFieldNameHere]. So, copy the query and add the criteria where necessary. That should get you want you want.

  3. #3
    Join Date
    Aug 2013
    Posts
    2
    Thanks for the help. HansUp from another site pointed out my tiny little flaw. I can't believe that I missed adding the WhereCondition - Jeeeez



    Private Sub PrintPerformance_Click() DoCmd.OpenReport "Rpt1 Performance", acViewPreview, _ WhereCondition:=Me.FilterEnd Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 10-01-2012, 12:31 PM
  2. Displaying query results in form
    By celito in forum Access
    Replies: 2
    Last Post: 08-27-2011, 09:14 AM
  3. Replies: 9
    Last Post: 12-13-2010, 09:25 PM
  4. Displaying query results within a form
    By Remster in forum Forms
    Replies: 5
    Last Post: 10-05-2010, 09:56 PM
  5. Replies: 0
    Last Post: 03-31-2010, 07:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums