Hello Lister,
I am currently attempting to create a copy of your example db but am having problems displaying it in a report.
First thing, though, my listbox is drawing its data from a tbl using a query statement rather than from a physical query.
I have a code behind my button that first tells the listbox to select all records (That part is working properly). Then I added your code below the first code. When I hit the button I get an "enter parameter" message for each field in my table.
Below is the code I am using:
Private Sub CreateReport_Click()
'First code to select all in listbox
For i = 0 To Listbox.Listcount = -1
Me.Listbox.Selected(i) = True
Next i
'Your code modified
On Error GoTo ErrHandler
Dim ctlSource As Control
Dim intCurrentRow, intStrLength As Integer
Dim strHolder As String
Dim vVal As Variant
Set ctlSource = Me.lstListedAMHidden
For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
vVal = ctlSource.Column(0, intCurrentRow)
End If
If vVal <> Empty Then
strHolder = strHolder & vVal & " Or tblAM.fldAssetID = "
vVal = Empty
End If
Next intCurrentRow
If strHolder <> ""
intStrLength = Len(strHolder) - 34
strHolder = Left(strHolder, intStrLength)
strHolder = " tblAM.fldAssetID = " & strHolder
DoCmd.OpenReport "rptListed", acViewPreview, , strHolder
Else 'If nothing was selected, run message.
MsgBox "A report cannot be generated", vbInformation, "Listbox Empty"
Me.lstListedAMHidden.SetFocus
End If
ExSub:
Do you see anything that could explain why it isn't working.