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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report Parameters Problem 1

Status
Not open for further replies.

TedRSki

Programmer
Oct 17, 2010
24
US
I looked through the Threads and found bits and pieces of some code for passing parameters to a report but it seems I still don't have it just right. The problem is I am using two textboxes for a Start Date and an End Date and a combo box for employee names. The report should only show the employee chosen and their days worked between the start date and the end date.

The code I have is this:


Private Sub Command21_Click()
On Error GoTo Err_Command21_Click

Dim stDocName As String
stDocName = "rpt_Emp_Wkly"

' Start Date Between #10/15/2010# And #10/16/2010#
' End Date Between #10/15/2010# And #10/16/2010#

Dim sCrit As String
If Len(Trim(Forms![frmReports]![Text0] & "")) Then
sCrit = "[SDate] Between #" _
& Forms![frmReports]![Text0] & "#"
End If
If Len(Trim(Forms![frmReports]![Text1] & "")) Then
If Len(sCrit) Then sCrit = sCrit & " And"
sCrit = sCrit & " #" _
& Forms![frmReports]![Text1] & "#"
End If
If Len(Trim(Forms![frmReports]![Text1] & "")) Then
sCrit = sCrit & " And [EDate] Between #" _
& Forms![frmReports]![Text0] & "#"
End If
If Len(Trim(Forms![frmReports]![Text1] & "")) Then
If Len(sCrit) Then sCrit = sCrit & " And"
sCrit = sCrit & " #" _
& Forms![frmReports]![Text1] & "#"
End If

' Employee Name = Alvarez, Juan

If Len(Trim(Forms![frmReports]![Combo19] & "")) Then
If Len(sCrit) Then sCrit = sCrit & " And"
sCrit = sCrit _
& " [EMPNAME] = '" _
& Forms![frmReports]![Combo19] & "'"
End If

DoCmd.OpenReport stDocName, acPreview, sCrit

Exit_Command21_Click:
Exit Sub

Err_Command21_Click:
MsgBox Err.Description
Resume Exit_Command21_Click
End Sub
 
DoCmd.OpenReport stDocName, acViewPreview, [!],[/!] sCrit

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV, Thank you very much for the quick and correct response. It has helped a lot. With the sCrit field for criteria, the report request is now working great. I can add as many or as few filters as I want. Thank you again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top