PDA

View Full Version : Help with LIKE and OR in some code



Mavver
01-17-2008, 07:49 AM
I am a self taught novice at coding and stuff, can someone please have a look at the following a see if you can see where I am going wrong.

An error box keeps popping up saying I have got the wrong syntax]

Thanks in advance

Mav


If Me!lstEOIType.ItemsSelected.Count > 0 Then
For Each varEOIType In Me!lstEOIType.ItemsSelected
strEOIType = strEOIType & " Or (qryEOIBase.type) Like '*" & Me!lstEOIType.ItemData(varEOIType) & "*'"
Next varEOIType
strEOIType = Right(strEOIType, Len(strEOIType) - 28)
strEOIType = " ((qryEOIBase.type) LIKE " & strEOIType & ")"
Else
LEOIType = MsgBox("You have not selected an Enquiry Type, do you wish to continue", vbYesNo, "Continue")
If LEOIType = vbYes Then
strEOIType = " qryEOIBase.type Like '*'"
Else
Exit Sub
End If
End If

rconverse
01-17-2008, 09:19 AM
What line are you receiving this error on?

This looks strange to me:



strEOIType = strEOIType & " Or (qryEOIBase.type) Like '*" & Me!lstEOIType.ItemData(varEOIType) & "*'"


Assuming Me!lstEOIType... is a text, you could try:



strEOIType = strEOIType & " Or (qryEOIBase.type) Like *""" & Me!lstEOIType.ItemData(varEOIType) & """*"


HTH
Roger

akn112
01-23-2008, 08:40 AM
it might be easier for us if you could do a break after your last end if statement and print out strEOIType from your immediate window.

Roger: i think wildcard should be kept inside the quotations. Also, the use of a single quote inside quotations is a shortcut to the string inside of a string. (ie: " ""*Hello*"" " = " '*Hello*' ")

Another thing worth mentioning is that if you are using ado to execute an sql statement, wildcards are represented by % as oppose to *