Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    May 2002
    Location
    Roanoke, Virginia, USA
    Posts
    493
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Selection Queries (A2K SP-3)

    Edited by HansV to correct formatting of conditions.

    I have a number of reports and forms that are based on the same fields but the selection criteria are different. For example:
    rptManagersReport is based on qryRentCalc
    rptWeeklyIncomeNoReceivables is based on qryRentCalcNoReceivables.

    In qryRentCalc the selection criteria on the field RentPaidDate is Between [ReportBeg] and [ReportEnd]

    In qryRentCalcNoReceivable there is an

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

    Re: Selection Queries (A2K SP-3)

    You can specify selection criteria in the instruction to open a report: DoCmd.OpenReport has an argument WhereCondition. It is a string that must look like the WHERE part of the SQL statement for a query, but without WHERE itself. So you can create a report based on a query without any parameters, and open the report with varying WhereConditions. Examples:

    Just open the report:
    DoCmd.OpenReport "rptMyReport", acViewPreview

    With a simple restriction:
    DoCmd.OpenReport "rptMyReport", acViewPreview, , "RentPaidDate Between [ReportBeg] And [ReportEnd]"

    With a more complex restriction:
    Dim strWhere As String
    strWhere = "(PayID = 1 Or PayID = 2) And (RentPaidDate Between [ReportBeg] And [ReportEnd])"
    DoCmd.OpenReport "rptMyReport", acViewPreview, , strWhere

  3. #3
    4 Star Lounger
    Join Date
    May 2002
    Location
    Roanoke, Virginia, USA
    Posts
    493
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selection Queries (A2K SP-3)

    The Switchboard Items table is used to specify the reports and forms

    For the rptManagersReport:

    SwitchboardID=7
    ItemNumber= 1
    ItemText= Weekly Income Sheet
    Command= 4
    Argument= rptManagersReport

    For the rptWeeklyIncomeNoReceivables:

    SwitchboardID=7
    ItemNumber= 2
    ItemText= Weekly Income

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

    Re: Selection Queries (A2K SP-3)

    You can find a complete listing of the values for Command in the code behind the Switchboard form:
    <hr>' Constants for the commands that can be executed.
    Const conCmdGotoSwitchboard = 1
    Const conCmdOpenFormAdd = 2
    Const conCmdOpenFormBrowse = 3
    Const conCmdOpenReport = 4
    Const conCmdCustomizeSwitchboard = 5
    Const conCmdExitApplication = 6
    Const conCmdRunMacro = 7
    Const conCmdRunCode = 8
    Const conCmdOpenPage = 9<hr>
    As you see, there is a constant for running code - the Switchboard Manager offers this option.

    However, I would do it slightly differently: I would create one or more forms on which the user can specify the parameters. Open a form from the Switchboard, and open the report from the form. Let's say that you have a form frmParameters with text boxes txtStartDate and txtEndDate (set the Format property for both to a date format), and a command button cmdOK. The On Click event procedure for the button would look like this:

    Private Sub cmdOK_Click()
    Dim strWhere As String

    On Error GoTo ErrHandler

    ' insert code to check the dates here, if you like.
    strWhere = "RentPaidDate Between [Forms]![frmParameters]![txtStartDate] And [Forms]![frmParameters]![txtEndDate]"
    DoCmd.OpenReport "rptMyReport", acViewPreview, , strWhere
    Exit Sub

    ErrHandler:
    If Not Err = 2501 Then ' ignore canceling the report
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

  5. #5
    4 Star Lounger
    Join Date
    May 2002
    Location
    Roanoke, Virginia, USA
    Posts
    493
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selection Queries (A2K SP-3)

    I don't think the operators would know which selection criteria go with which report. I want the operator to be able to view/print a report by just knowing the name of the report.

    Many thanks for the command listings. I will see what I can do with command 8.

    Tom

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

    Re: Selection Queries (A2K SP-3)

    You can give the switchboard menu item the name of the report, still call the corresponding form. But it's up to you to decide.

Posting Permissions

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