469,126 Members | 1,268 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,126 developers. It's quick & easy.

Inputting age range through text boxes to generate report

68 64KB
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?
Dec 5 '12 #1
2 1396
5,400 Expert Mod 4TB
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.
Dec 5 '12 #2
32,161 Expert Mod 16PB
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 :
    Expand|Select|Wrap|Line Numbers
    1. strWhere = "([Age] Between #%F# And #%T#)"
    2. strWhere = Replace(strWhere, "%F", Format([FromAge], "m\/d\/yyyy")
    3. 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 :
    Expand|Select|Wrap|Line Numbers
    1. Call DoCmd.OpenReport(ReportName:=rptXXX, _
    2.                       View:=acPreview, _
    3.                       WhereCondition:=strWhere)
This should open your report with only valid records included.

PS. Please remember to post all the required information in future questions.
Dec 5 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Mark | last post: by
4 posts views Thread by Andrew Meador - ASCPA, MCSE, MCP+I, Network+, A+ | last post: by
6 posts views Thread by noe1818 via AccessMonster.com | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.