Hi Dirk!
Hi, Jan! Merry Christmas!
Dirk Goldgar said:
[...] Try this:
stCriteria = "JobDate Between " & _
Format(Forms!frmLaborFilter!Text62, "\#mm/dd/yyyy\#") & _
" AND " & _
Format(Forms!frmLaborFilter!Text64, "\#mm/dd/yyyy\#")
I have done a copy and paste of this code into the command button on
the frmLaborCosts that should open the rptLaborCosts report for
preview. But, it is printing it instead and I can't preview it.
Although, it is still printing out all the records, not just those
for the criteria as entered from the frmLaborFilter or the
frmLaborCosts for that specific set of records to print out.
I can't help thinking that either the code isn't being executed at all,
or there's something else wrong with it. I haven't followed this thread
from top to bottom, so I don't know what-all has gone before. Please
post the complete code from the command button's Click event procedure.
Set a breakpoint and verify, if you would, that this code is actually
being executed. Also post any code that may exist in the report's Open
event.
There is no code in the Open Event of the rptLabotCosts form.
Here is the code in the On click event for the command button that is on the
frmLaborCosts to preview the report. I recreated the button, and it will now
preview, but, all records are shown, not the selected ones as is on the
frmLaborCosts where the button is located:
**********************Begin Code************************
Private Sub cmdRptPreview_Click()
On Error GoTo Err_cmdRptPreview_Click
Dim stDocName As String
stCriteria = "JobDate Between " & _
Format(Forms!frmLaborFilter!Text62, "\#mm/dd/yyyy\#") & _
" AND " & _
Format(Forms!frmLaborFilter!Text64, "\#mm/dd/yyyy\#")
stDocName = "rptLaborCosts"
DoCmd.OpenReport stDocName, acPreview
Exit_cmdRptPreview_Click:
Exit Sub
Err_cmdRptPreview_Click:
MsgBox Err.Description
Resume Exit_cmdRptPreview_Click
End Sub
******************End Code*********************
The code behind the command button on the frmLaborFilter that opens the
frmLaborCosts after the criteria has been entered in the controls is:
***************************Begin Code**********************
Private Sub cmdExpResearch_Click()
On Error GoTo Err_cmdExpResearch_Click
Dim strWhere As String
Dim stDocName As String
Dim stLinkCriteria As String
strWhere = ""
If IsNull(Me!cmbJobLocation) = False Then
strWhere = "[JobLocation]=" & "'" & Me![cmbJobLocation] & "'"
End If
Me![cmbJobLocation] = Null
If IsNull(Me!cmbJobType) = False Then
If strWhere <> "" Then strWhere = strWhere & " and "
strWhere = strWhere & "[JobType]=" & "'" & Me![cmbJobType] & "'"
End If
Me![cmbJobType] = Null
If IsNull(Me!cmbContractorName) = False Then
If strWhere <> "" Then strWhere = strWhere & " and "
strWhere = strWhere & "[ContractorName]=" & "'" & Me![cmbContractorName]
& "'"
End If
Me![cmbContractorName] = Null
If IsNull(Me!cmbEmpName) = False Then
If strWhere <> "" Then strWhere = strWhere & " and "
strWhere = strWhere & "[EmpName]=" & "'" & Me![cmbEmpName] & "'"
End If
Me![cmbEmpName] = Null
stDocName = "frmLaborCosts"
stLinkCriteria = strWhere
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmdExpResearch_Click:
Exit Sub
Err_cmdExpResearch_Click:
MsgBox Err.Description
Resume Exit_cmdExpResearch_Click
End Sub
*************************End Code********************
I have run the breakpoint and the code appears to be firing.
Don't know if you need this information, but, the query behind the
frmLabotCosts and rptLaborCosts is based upon a table where records are
entered from a data entry form. The query SQL is;
SELECT tblLaborCosts.EmpName, tblLaborCosts.EmpID, tblLaborCosts.JobDate,
tblLaborCosts.ContractorName, tblLaborCosts.JobType,
tblLaborCosts.JobLocation, tblLaborCosts.Manhours, tblLaborCosts.HourlyRate,
Sum([Manhours]*[HourlyRate]) AS TotalCost
FROM tblLaborCosts
GROUP BY tblLaborCosts.EmpName, tblLaborCosts.EmpID, tblLaborCosts.JobDate,
tblLaborCosts.ContractorName, tblLaborCosts.JobType,
tblLaborCosts.JobLocation, tblLaborCosts.Manhours, tblLaborCosts.HourlyRate
HAVING (((tblLaborCosts.JobDate) Between [Forms]![frmLaborFilter]![Text62]
And [Forms]![frmLaborFilter]![Text64])) OR
((([Forms]![frmLaborFilter]![Text62]) Is Null)) OR
((([Forms]![frmLaborFilter]![Text64]) Is Null));
If you wish, as a ref of the basic structure of the frmLaborFilter form, you
can see the Purchasing Filter form in the MOW db. The structure is
basically the same, with different names and data sources, and I added the
command button with the research code on the frmLaborFilter. This may give
you an idea of how the criteria is entered in the controls for the sets of
records to be viewed and printed by the report.
Thank you,
Jan