OutputTo Statement/Query not working

P

Paige_Franklin

I have a form with a listbox. The user selects items from the list box and
it calls a query that is supposed to find records based on the list box
responses. The list box returns the numeric id of the record which works
fine when there is only one selection. If more than one item in the box is
selected and I try to call the query - I get an error because I am passing a
string to the query instead of the ID Numbers. For example - looking for
records 1 and 10. It seems to be passing "1 and 10" as the string. It
doesn't look that way in the message box so I'm not sure how to fix this.

The query works fine just entering the numbers manually - I just can't get
the form to pass the numbers correctly when there are more than one.

Here is the code:

Private Sub Command17_Click()
On Error GoTo Err_Command17_Click
Dim blnSelected As Boolean
Dim strEmpID As String
Dim strDateRange As String
Dim varItm As Variant

' pre set blnSelected
blnSelected = True
' end

'Clear variables & screen fields
strEmpID = ""
strDateRange = ""
' Me.txtDateRange = ""
Me.txtEmpID = ""

If List1.ItemsSelected.Count > 0 Then
For Each varItm In List1.ItemsSelected
If strEmpID = "" Then
strEmpID = (List1.ItemData(varItm))
Else
strEmpID = strEmpID & " OR " & (List1.ItemData(varItm))
End If
Next varItm
Me.txtEmpID = strEmpID
MsgBox ("Emp ID : " & strEmpID)

If IsNull(Ending_Date) Or [Ending_Date] = "" Then
DoCmd.OutputTo acOutputQuery, "qry_Summary_Export", acFormatXLS, ,
True
Else
DoCmd.OutputTo acOutputQuery, "qry_Summary_Export2", acFormatXLS, ,
True
End If

Else ' For All Employers
If IsNull(Ending_Date) Or [Ending_Date] = "" Then
DoCmd.OutputTo acOutputQuery, "qry_Summary_Export3", acFormatXLS, ,
True
Else
DoCmd.OutputTo acOutputQuery, "qry_Summary_Export4", acFormatXLS, ,
True
End If
End If

Exit_Command17_Click:
Exit Sub

Err_Command17_Click:
MsgBox Err.Description
Resume Exit_Command17_Click

End Sub
 

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