Missing Operator

K

Kenny G

Hello,

I keep getting a message: syntax error(missing operator) in query
expression '(Location = OR Location = OR)'.

Below is the code under the command button. I have a multiselect list box
with this as well.

Is there something wrong with my code?

Thanks for your help.

Private Sub cmdLocationandStandardsReport_Click()

Dim ctl As Control
Dim var As Variant
Dim strSQL As String
Dim strIdentifier As String
Set ctl = Me.lstSiteLocation
strIdentifier = "Location = "
'check for selection
If ctl.ItemsSelected.Count = 0 Then
MsgBox "Please Make A Selection or Selections.", vbOKOnly, "Error"
Exit Sub
End If
'cycle through selected items
'to build SQL WHERE expression
For Each var In ctl.ItemsSelected
strSQL = strSQL & strIdentifier & ctl.ItemData(var) & " OR "
'Added Next
Next
'Test right 3 characters for " OR ", remove if found
If Right$(strSQL, 3) = " OR " Then
strSQL = Left$(strSQL, Len(strSQL) - 3)
End If

DoCmd.OpenReport "Location and Standards Report", acViewPreview, ,
strSQL

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