List box selection with date selection

A

Anne

I have two seperate requests for reports, the first report selects items
from a list box and prints the report. The second selects a date range, but
orginally asked to select an employee from a combobox.
I have been trying to combine the listbox selection with a date range
selection, but the results are not what I am asking for, neither the date
range or the names selected appear on the report. -The code is below
Can someone help?
Anne

Private Sub CmdPrint_Click()
Dim varSelected As Variant
Dim strSQL As String
For Each varSelected In Me!lstSelect.ItemsSelected
strSQL = strSQL & Me!lstSelect.ItemData(varSelected) & ","
Next varSelected
If strSQL <> "" Then
strSQL = "[EmployeeId] IN (" & Left(strSQL, Len(strSQL) - 1) & ")"
'''''''''''DoCmd.OpenReport "DetailbyEmplbyWeek", acViewPreview, ,
strSQL
----------------------this is where the list selection by itself
ended----------------
End If
If Not IsNull(Me!txtDateFrom) Then
strWhere = strWhere & " AND [WeDate] >= #" & _
CDate(Me!txtDateFrom) & "#"
End If
If Not IsNull(Me!txtdateto) Then
strWhere = strWhere & " AND [WeDate] <= #" & _
CDate(Me!txtdateto) & "#"
End If
DoCmd.OpenReport "DetailbyEmplbyWeek", acViewPreview, , strSQL
End Sub
 
T

Terry

Hello Anne
It looks OK to me. If you break it into single parts, for example, include
the code for only the list box, then only the code for the From Date..., do
each of the individual parts run OK?

The only part that worries me is the dates. Dates are a bit of a mish mash
if you are not using US dates. I like to change the format to 'Medium Date'
to check what is happening. Check that they are converting correctly as you
step through

I would be inclined to put a break point on the For Each line and step
though the build checking the values as they are generated. You may also like
to 'Watch' the values.
HTH
Terry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top