Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open report with criteria

Status
Not open for further replies.

vols77

Technical User
Feb 17, 2007
29
US
Forgive me if this is the wrong forum but this does deal with reports so I thought I would give it a shot here.

The below code opens the report fine, however, how would I incorporate text22 and text24, which are two fields that the user can use to enter a date range. Also, if possible, how would I tell it that if no date range is used, use all data?
I was going to use a simple between x and x in the query to do a date range but it has been requested to have it on the form for "looks".

DoCmd.OpenReport "rptjobs", acViewPreview, , "Job='" & Me!List16 & "'"
DoCmd.Close acForm, "switchboard"


Thanks for any help!
 
You should have provided the name of your date field as well as renamed your date text boxes and your list box. Then use code like:

Code:
Dim strWhere as String
strWhere = "Job='" & Me!lboJob & "'"
If not IsNull(Me.txtStart) Then
    strWhere = strWhere & " AND [DateField]>=#" & _
        Me.txtStart & "#"
End If
If not IsNull(Me.txtEnd) Then
    strWhere = strWhere & " AND [DateField]<=#" & _
        Me.txtEnd & "#"
End If
DoCmd.OpenReport "rptjobs", acViewPreview, , strWhere

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top