I did not see your second reply when I wrote at about the query earlier. I
would prefer the form anyway, so I will try this in the morning.
Actually I am already using a combobox to select either one employee or one
job and then I let the query take care of the date. I created another combo
for the dates and either combo works fine, but I cannot get the report to
accept the dates and the name combined because I don't know how to add a
second code.
Private Sub Pirnt1_Click()
Dim strWhere As String
If IsNull(cboMoveTo) = False Then
strWhere = "[Jobno] = " & cboMoveTo
End If
DoCmd.OpenReport "YTDbyJobSEformat", acViewPreview, , strWhere
End Sub.
This is my on print event for the job number, how can I hang on the code for
the date
Annelie
Unless you're using the Report from other than this button, I'd
suggest basing the Report on a Query which uses the form controls as
criteria, as suggested in my previous message; then you don't need a
strWhere at all, just open the Report and it will look to the form.
Alternatively, you can pass the date criteria in strWhere itself. This
will require some more complexity since you will need to construct a
valid SQL WHERE clause, with several criteria. Air code here,
untested:
Dim strWhere As String
strWhere = "True" ' so records will be retrieved if no other
' criteria are entered
If Not IsNull(Me!cboMoveTo) Then
strWhere = strWhere & " AND [JobNo] = " & Me!cboMoveTo
End If
If Not IsNull(Me!txtDateFrom) Then
strWhere = strWhere & " AND [datefield] >= #" & _
CDate(Me!txtDateFrom) & "#"
End If
If Not IsNull(Me!txtDateTo) Then
strWhere = strWhere & " AND [datefield] <= #" & _
CDate(Me!txtDateTo) & "#"
End If
So if someone selects a number from the combo and types dates (in
whatever recognizable form, which CDate will convert to a valid date
value) strWhere will come out like
True AND [JobNo] = 345 AND [Datefield] >= #1/1/2003# AND [Datefield]
<= #10/1/2003#
I put the TRUE in there because a WHERE string starting with the word
AND would be erroneous.