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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"In" keyword equivalent in VBA

Status
Not open for further replies.

RealKiwi

Technical User
Feb 26, 2004
41
NZ
Is there a VBA eqivalent to the 'In' SQL keyword, or am I resigned to using lengthy 'or' statements?

Code:
SELECT *
FROM tblName
WHERE fieldname IN ('ax', 'bx', 'cx', dx')

thanks
 
If your dealing with a set of data like 'ax', 'bx', 'cx', dx', the Split function comes in pretty handy. Is in the help file.
 
And what about something like this?
Select Case varname
Case "ax", "bx", "cx", "dx"
' Your code here
End Select

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Yet another cryptic help file from Microsoft... not surprise there ;-)
 
Thanks PHV, I had that in mind; even had the 6 code lines to do the job. 'In' is so much cleaner! :)
 
You can also use InStr to cheat a bit for strings.
[blue][tt]
If Instr ( "ax?bx?cx?dx?", myString & "?" ) > 0 then
[/tt][/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top