Type Mismatch

jackieann

New member
Local time
Today, 14:26
Joined
Aug 24, 2015
Messages
3
I keep playing around with this code and keep getting an error message "Type Mismatch" when trying to run the query. The code error is on the line after 'Else'. Does anyone know how this needs to be modified? Thanks

If Me!lstRRep.ItemsSelected.Count > 0 Then
For Each varItem In Me!lstRRep.ItemsSelected
strCriteria5 = strCriteria5 & "SalesbyRSM3.Relay_Rep = " & Chr(34) _
& Me!lstRRep.ItemData(varItem) & Chr(34) & "OR "
Next varItem
strCriteria5 = Left(strCriteria5, Len(strCriteria5) - 3)
Else
strCriteria5 = "SalesbyRSM3.Relay_Rep Like '3'" Or "SalesbyRSM3.Relay_Rep" Is Null
End If
 
Ever see the movie Inception? Building strings is like that. You have to know if you are in a literal or outside a literal and know when you have been kicked back up a level.

Here's the rules-

- when you build strings you can use 2 parts: literals and variables.

- you can combine those however you want, but when you switch from one to the other you have to put an ampersand (&) between them

-A literal is put into the string when you have a pair of double quotes. Everything between the first and second will appear in the string as it appears between the quotes

-a variable puts the value it contains into the string.

You haven't constructed your string according to those rules. You set the value of strCriteria5 3 times in that code. The first and second look syntatically good, but in that 3rd one I count 4 double quotes and see no ampersands. That means you have incorrectly concatenated things. I see no variables used at all, so it would seem the whole thing is a literal, which means you should only be using 2 double quotes.

Give it another shot.

Oh, and you have more issues than that. You're loop isn't building what you think its building.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom