473,326 Members | 2,114 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,326 software developers and data experts.

IIF problem in Access query builder; syntax error

Tabasco
25
Hello everyone ive a problem with an IIF statement which i try to use in access quary builder.

I put this in the field and ive also tried a textbox

Expand|Select|Wrap|Line Numbers
  1. =IIF(CountOfParticipant_id1 > 1, "TRUE", "FALSE")
ive also tried this

Expand|Select|Wrap|Line Numbers
  1. IIF(CountOfParticipant_id1 > 1, "TRUE", "FALSE")
Expand|Select|Wrap|Line Numbers
  1. =IIF([CountOfParticipant_id1] > 1, "TRUE", "FALSE")
Expand|Select|Wrap|Line Numbers
  1. IIF([CountOfParticipant_id1] > 1, "TRUE", "FALSE")

but i always get syntax error
"the expression you entered contains invalid syntax. You may have entered an operand without an operator"

PS
I am trying to create a new field with this IIF statement
DS
Dec 20 '12 #1

✓ answered by zmbd

In the query builder with an expression you need something like this in the first row of the grid:
ThisIsAlias: IIF([CountOfParticipant_id1] > 1, "TRUE", "FALSE")

The SQL:
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.    IIF([CountOfParticipant_id1] > 1, "TRUE", "FALSE")
  3.      AS ThisIsAlias
  4. FROM tbl_whattablethefieldisin;
Yep... so, compare these two against what you have.

7 5367
zmbd
5,501 Expert Mod 4TB
In the query builder with an expression you need something like this in the first row of the grid:
ThisIsAlias: IIF([CountOfParticipant_id1] > 1, "TRUE", "FALSE")

The SQL:
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.    IIF([CountOfParticipant_id1] > 1, "TRUE", "FALSE")
  3.      AS ThisIsAlias
  4. FROM tbl_whattablethefieldisin;
Yep... so, compare these two against what you have.
Dec 20 '12 #2
Tabasco
25
i work just great to write it in SQL but it didn't when i didt write it in the first field, wierd, maybee thats the key it never crossed my mind to wright to IIF statment in SQL, thank you zmbd for the help! :-)


[Z{ Texting/Grammer to standard English fix:(
It worked just great when I wrote this in SQL; however, it didn't work when I tried this in the first field of the editor. Weird. Maybe that's the key, it never crossed my mind to write the IIF statement in SQL! Thank you zmbd for the help! :-) )}]
Dec 20 '12 #3
zmbd
5,501 Expert Mod 4TB
The key is the Alias ( "ThisIsAlias:" ).

If you go into the SQL view of the editor and enter the SQL, when you go back the table-design view you'll see the "AS" portions converted to the nameas-colon convention.

SQL is however a very good thing to master. Keep in mind; however, that MS Access doesn't use the entire standard SQL set so a few things are either implemented using a slightly different syntax or outright not supported.
Dec 20 '12 #4
NeoPa
32,556 Expert Mod 16PB
Tabasco,

Whether you realise it or not, what you enter into a query field is always SQL! Access provides a graphical way for you to express what you want, but this is stored internally as SQL. Any time you are looking at a query in Access you can switch to SQL-View to see how Access has converted your requirements into SQL.

Z was explaining to you how what you see in the design view equates to the SQL it creates. The IIf() command is always called from the SQL though, whichever way you look at it.
Dec 20 '12 #5
Tabasco
25
I think i understand, If you want to use a IIF() statement you have to give it an Alias, right? I have no doubt that SQL would be vary useful indeed so I'll try to write in sql view rather in design view so i'll get better. Thanks again zmdb!

Yes, thanks NeoPa, i knew that what you wrote in access design view was sql, however I failed to see the connection between sql and design view and look at my problem from another approch. This will be very useful when i encounter other problems! :-)
Dec 22 '12 #6
zmbd
5,501 Expert Mod 4TB
Yes you have that correct for the IIF; however, this is true for any equation/function that you attempt to use as a field.

As for programing exclusively in the SQL mode for Access... please don't drop the design view from your "toolbox" it is simply too useful in the type saving. In-fact I use it quite a bit of the time... sometimes for just a simple select query, other times to build the basics of what I need and then go into the SQL mode to do the things that are either difficult in design view or not directly supported.
Dec 22 '12 #7
NeoPa
32,556 Expert Mod 16PB
I would support Z's last comment about working exclusively in SQL. While it can help your learning if you always view what the query-builder creates as far as the SQL goes, it's still a useful tool. Some things it simply cannot handle, and having SQL skills to fill those gaps is very useful, but so too is having the query-builder, as it's so much quicker and easier for the more straightforward queries.

I should also add that I've switched the posts selected for Best Answer. Tabasco showed he was aware that Z had helped the most, but selected a post that wasn't appropriate. The new one is and reflects the answer most closely.
Dec 23 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
9
by: Sudesh Sawant | last post by:
Hello, We have an application which communicates using remoting. There is a server which is a Windows Service. The server exposes an object which is a singleton. The client is a Web Application...
117
by: Peter Olcott | last post by:
www.halting-problem.com
0
by: James Griffiths | last post by:
Here is a report I've written about a printing problem that is being experienced by a particular company for whom I had developed a A97 system. After upgrading to Win XP and AXP, some printing...
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.