473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

using 'IN' in a vba if statement

Hi,

In a query one can use the 'IN' operator but how can I do the same
thing in a if statement?? as in the below which does not work.

if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then

thanks
bobh.

Aug 14 '07 #1
13 28421
On Aug 14, 11:02 am, bobh <vulca...@yahoo.comwrote:
Hi,

In a query one can use the 'IN' operator but how can I do the same
thing in a if statement?? as in the below which does not work.

if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then

thanks
bobh.
maybe I answered my own question with;

If MyRec!ClmTyp = "p" And MyRec!PolSym = (I Or K Or O Or P Or Q Or R
Or S Or Z) Then

Aug 14 '07 #2
bobh wrote:
Hi,

In a query one can use the 'IN' operator but how can I do the same
thing in a if statement?? as in the below which does not work.

if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then

thanks
bobh.
You'll need the Like operator, something like this

.... and MyRec!PolSym Like "[IKOPQRSZ]" then

which should work, I think, if the PolSym field contains only
one letter.

--
Roy-Vidar
Aug 14 '07 #3
On Aug 14, 11:52 am, bobh <vulca...@yahoo.comwrote:
On Aug 14, 11:02 am, bobh <vulca...@yahoo.comwrote:
Hi,
In a query one can use the 'IN' operator but how can I do the same
thing in a if statement?? as in the below which does not work.
if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then
thanks
bobh.

maybe I answered my own question with;

If MyRec!ClmTyp = "p" And MyRec!PolSym = (I Or K Or O Or P Or Q Or R
Or S Or Z) Then

I spoke too soon cause this doesn't work either
If MyRec!ClmTyp = "p" And MyRec!PolSym = (I Or K Or O Or P Or Q Or R
Or S Or Z) Then <<


Aug 14 '07 #4
if PolSym is a text data type you need quote marks around the criteria:

.... in ('I','K','O','P','Q','R','S','Z')
bobh wrote:
Hi,

In a query one can use the 'IN' operator but how can I do the same
thing in a if statement?? as in the below which does not work.

if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then

thanks
bobh.
Aug 14 '07 #5
Hi,
Yes polsym is text but " in ('I','K','O','P','Q','R','S','Z') " does
not work in the vba if statement.
thanks
bobh.

On Aug 14, 1:25 pm, John Winterbottom <john...@rogers.cawrote:
if PolSym is a text data type you need quote marks around the criteria:

... in ('I','K','O','P','Q','R','S','Z')

bobh wrote:
Hi,
In a query one can use the 'IN' operator but how can I do the same
thing in a if statement?? as in the below which does not work.
if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then
thanks
bobh.- Hide quoted text -

- Show quoted text -

Aug 14 '07 #6
I think the problem is not with the IN operator. Try printing the
vb-generated sql string to the debug window and copy into a query and
run it from there

bobh wrote:
Hi,
Yes polsym is text but " in ('I','K','O','P','Q','R','S','Z') " does
not work in the vba if statement.
thanks
bobh.

On Aug 14, 1:25 pm, John Winterbottom <john...@rogers.cawrote:
>if PolSym is a text data type you need quote marks around the criteria:

... in ('I','K','O','P','Q','R','S','Z')

bobh wrote:
>>Hi,
In a query one can use the 'IN' operator but how can I do the same
thing in a if statement?? as in the below which does not work.
if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then
thanks
bobh.- Hide quoted text -
- Show quoted text -

Aug 14 '07 #7
On Tue, 14 Aug 2007 08:02:41 -0700, bobh wrote:
Hi,

In a query one can use the 'IN' operator but how can I do the same
thing in a if statement?? as in the below which does not work.

if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then

thanks
bobh.
If I recall correctly, In is not a VBA operator, so it's not
recognized in VBA.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Aug 14 '07 #8
On Tue, 14 Aug 2007 10:08:45 -0700, bobh wrote:
On Aug 14, 11:52 am, bobh <vulca...@yahoo.comwrote:
>On Aug 14, 11:02 am, bobh <vulca...@yahoo.comwrote:
>>Hi,
>>In a query one can use the 'IN' operator but how can I do the same
thing in a if statement?? as in the below which does not work.
>>if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then
>>thanks
bobh.

maybe I answered my own question with;

If MyRec!ClmTyp = "p" And MyRec!PolSym = (I Or K Or O Or P Or Q Or R
Or S Or Z) Then

I spoke too soon cause this doesn't work either
>If MyRec!ClmTyp = "p" And MyRec!PolSym = (I Or K Or O Or P Or Q Or R
Or S Or Z) Then <<
No that won't work either.
You need to include the criteria field with each value.
Note the parenthesis placement as well.

If MyRec!ClmTyp = "p" And (MyRec!PolSym = "I" Or MyRec!PolSym = "K"
Or MyRec!PolSym = "O" Or MyRec!PolSym = "P" etc... ) then
should work.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Aug 14 '07 #9

"bobh" <vu******@yahoo.comwrote in message
news:11*********************@r34g2000hsd.googlegro ups.com...
Hi,

In a query one can use the 'IN' operator but how can I do the same
thing in a if statement?? as in the below which does not work.

if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then

thanks
bobh.
IF MyRec!ClmTyp="p" and instr(1, "I,K,O,P,Q,R,S,Z", MyRec!PolSym)>0 then

Note the commas in "I,K,O,P,Q,R,S,Z" are not needed and can cause error if
the value of [PolSym] can be comma.
Aug 14 '07 #10
On Aug 14, 2:33 pm, fredg <fgutk...@example.invalidwrote:
On Tue, 14 Aug 2007 08:02:41 -0700, bobh wrote:
Hi,
In a query one can use the 'IN' operator but how can I do the same
thing in a if statement?? as in the below which does not work.
if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then
thanks
bobh.

If I recall correctly, In is not a VBA operator, so it's not
recognized in VBA.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
I believe fredg is correct.

How about:

If CStr(Nz(MyRec!ClmTyp,"")) = "p" Then
Select Case CStr(Nz(MyRec!PolSym, ""))
Case "I", "K", "O", "P", "Q", "R", "S", "Z":
'do stuff
End Select
End If

James A. Fortune
CD********@FortuneJames.com

Aug 14 '07 #11
bobh wrote:
Hi,
Yes polsym is text but " in ('I','K','O','P','Q','R','S','Z') " does
not work in the vba if statement.
thanks
bobh.

On Aug 14, 1:25 pm, John Winterbottom <john...@rogers.cawrote:
>>if PolSym is a text data type you need quote marks around the criteria:

... in ('I','K','O','P','Q','R','S','Z')

bobh wrote:
>>>Hi,
>>>In a query one can use the 'IN' operator but how can I do the same
thing in a if statement?? as in the below which does not work.
>>>if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then
>>>thanks
bobh.- Hide quoted text -

- Show quoted text -


Why not use Instr()
And Instr("ABCDEFG","A:) 0
Aug 14 '07 #12
bobh <vu******@yahoo.comwrote in
news:11*********************@r34g2000hsd.googlegro ups.com:
Hi,

In a query one can use the 'IN' operator but how can I do the
same thing in a if statement?? as in the below which does not
work.

if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then

thanks
bobh.
the instr() function returns the position of a specified string
within another string, or a 0 if not found.

if instr("IKOPQRSZ",MyRec!PolSym) >0 then

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 15 '07 #13
This worked..... :) Thanks!
bobh.

On Aug 14, 3:22 pm, "paii, Ron" <n...@no.comwrote:
"bobh" <vulca...@yahoo.comwrote in message

news:11*********************@r34g2000hsd.googlegro ups.com...
Hi,
In a query one can use the 'IN' operator but how can I do the same
thing in a if statement?? as in the below which does not work.
if MyRec!ClmTyp="p" and MyRec!PolSym in (I,K,O,P,Q,R,S,Z) then
thanks
bobh.

IF MyRec!ClmTyp="p" and instr(1, "I,K,O,P,Q,R,S,Z", MyRec!PolSym)>0 then

Note the commas in "I,K,O,P,Q,R,S,Z" are not needed and can cause error if
the value of [PolSym] can be comma.

Aug 15 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bob | last post by:
Currently I am using this statement to translate 3 fields in my db thru Visual Basic. I import the data from one table to another then call the IFF statements and the NewDate to translate the...
3
by: Peter Phelps | last post by:
My problem is as follows: I need automatically iterate through a single field in a table and use the values in the field to create an in-statement. Currently, the character limitation in the...
2
by: bashanitwonline | last post by:
Hi All, I have DB2 8.1 on my system. I have created a procedure as follows. CREATE PROCEDURE DB2ER000.XYZ() LANGUAGE SQL BEGIN INSERT INTO DB2ER000.A ( C,D,E) VALUES (10,20,30); END It...
0
by: Lavs | last post by:
Hi Guys... Is there anyone who could help me on how to add an image file to a database using SQL Statement... I am using a database in MS ACCESS 2003, and my application was designed in VB 6.0. I...
0
by: brainfulkale | last post by:
My question is that "How to print on VDU without using printf statement in unix" In DOS i use far pointer as cls { char far *s; s=0xB8000000; *s='A'; } But if i wanted to print in unix jow...
5
by: konaravikumar | last post by:
writing a query to get the second highest value in atable by using select statement
1
by: =?Utf-8?B?bGlhbnF0bGl0?= | last post by:
Is using a jump statement more faster than using if statement with a jump statement example for(int i=0; i < 10; i++) { if(a == null) {
1
by: bcap | last post by:
Is it possible to create a SQL In statement using variables? For example, here is what can be done: SELECT Test.ID, Test.Desc FROM Test WHERE (((Test.ID) In (3,6,9,12))); But, I would...
8
reginaldmerritt
by: reginaldmerritt | last post by:
Hi, I have two report layouts that are used to run 12 different reports using where statement. for example DoCmd.OpenReport "SomeReport", _ acViewPreview, _ ...
2
by: lenniekuah | last post by:
Hullo Good Friends, I am back again seeking help. Please help me. I am using C#NET2008 Window Application, This is the situation. Should either one of this control, txtXMLFolder.Text ,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.