Inputting age range through text boxes to generate report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Stoic
    New Member
    • Jun 2012
    • 68

    #1

    Inputting age range through text boxes to generate report

    Hi,
    I have database in access 2007 with an 'Age' field. Now I a Form with two fields (Beginning Age and Ending Age) and a control button that when I entered the two ages in both fields and click the control button, it will generate a report of individuals that fall within that age range.

    Any help on this?
    Thanks
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    You have a very general question; thus, the best I can do is tell you to use a "Select" query and I'd more than likly use the "Between" conditional or ">=" "<=" in some manner depending on the table design.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      One must assume, as you've left out most of the important details of the question, that you have a report built on a data source which has some sort of an [Age] field. You also have [FromAge] and [ToAge] controls on your form.

      In such a situation you can run code behind the Command Button which :
      1. Formulates a Criteria string using code similar to :
        Code:
        strWhere = "([Age] Between #%F# And #%T#)"
        strWhere = Replace(strWhere, "%F", Format([FromAge], "m\/d\/yyyy")
        strWhere = Replace(strWhere, "%T", Format([ToAge], "m\/d\/yyyy")
        See Literal DateTimes and Their Delimiters (#) for help with formatting dates for SQL.
      2. Open the report passing the criteria in your call using code similar to :
        Code:
        Call DoCmd.OpenReport(ReportName:=rptXXX, _
                              View:=acPreview, _
                              WhereCondition:=strWhere)

      This should open your report with only valid records included.

      PS. Please remember to post all the required information in future questions.

      Comment

      Working...