Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter a Report based on List Box

Status
Not open for further replies.

larze

Programmer
May 23, 2005
1
US
Could someone please tell me where to add the (") in the following code:

stDocCriteria = stDocCriteria & "[Location] = " & listlocation.Column(0, VarItm) & " OR "

so that the entire code below will filter correctly.

Currently my filter ([Location] = Boston)is incorrect it should be ([Location] = "Boston" )

Thanks in advance for your help.

Here's the entire code:

Private Function GetCriteria() As String

Dim stDocCriteria As String
Dim VarItm As Variant
For Each VarItm In listlocation.ItemsSelected
stDocCriteria = stDocCriteria & "[Location] = " & listlocation.Column(0, VarItm) & " OR "
Next
If stDocCriteria <> "" Then
stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 4)
Else
stDocCriteria = "True"
End If
GetCriteria = stDocCriteria
End Function
___________________________________________________________
Private Sub ButtonOpen_Click()
DoCmd.OpenReport "Location", acPreview, , GetCriteria()
End Sub
 
It should probably be ([Location] = 'Boston') - single quotes:

[tt]stDocCriteria = stDocCriteria & "[Location] = '" & listlocation.Column(0, VarItm) & "' OR "[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top