Runtime error - DoCmd.OpenReport

R

Robert Bain

I am trying to print a report (rptMultiRouteSlip) with
only selected employees. I am using multiple selections
from a list box (List0) on Form1 to select the employees.
The list box contains the EID, first name, last name,
department name, and mailstop codes from tblEmployee. The
bound field is the employeeID (EID) field. I've set the
list box to allow for multiple select. I added a command
button to select the employee id's from the list box and
create a WHERE clause. When I debug.print(strList)I get
the WHERE clause I'm looking for. But, I keep getting a
compile error when I try to execute the last line of the
following code. It indicates that it is expecting an =
sign. If I don't enclose the last line report name,
view, , and where clause in parenthesis I get a run time
error that says the expression is too complex to
evaluate.

Private Sub Command4_Click()
Dim strList As String
Dim varItm As Variant
Dim strReportName As String
strReportName = "rptMultiRouteSlip"
strList = " EID In("
For Each varItm In Me.List0.ItemsSelected
strList = strList & Me.List0.ItemData(varItm) & ","
Next varItm
strList = Left(strList, Len(strList) - 1) & ")"
'Debug.Print (strList)
DoCmd.OpenReport(strReportName, acViewPreview,,strList)
End Sub

Any help you can offer would be great.

Thanks,
RCB
 

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