424,066 Members | 2,120 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,066 IT Pros & Developers. It's quick & easy.

"The expression you entered contains invalid syntax."

P: 1
Can someone please help me? I am making a system through Microsoft Access 2016 for school and I am having trouble writing this expression. If you could help me ASAP that would be amazing.

The expression is so that if the field "Maximum Capacity" is equal to 1, then the value in the field "Private Lesson" will equal to Yes or True.

This is what I have made so far but I don't understand how to write expressions so could anyone help me?


Expand|Select|Wrap|Line Numbers
  1. = True IIf( ([Maximum Capacity] =1, <1=False )
When I try to enter the code in the builder, the error message says
"The expression you entered contains invalid syntax.
You may have entered an operator, such as the + operator, in an expression without a corresponding operand."

Thank you!
Dec 17 '18 #1

✓ answered by twinnyfo

tam21

Welcome to Bytes!

Your expression should be

Expand|Select|Wrap|Line Numbers
  1. = ([Maximum Capacity] = 1)
Hope this hepps!

Share this Question
Share on Google+
8 Replies


twinnyfo
Expert Mod 2.5K+
P: 2,780
tam21

Welcome to Bytes!

Your expression should be

Expand|Select|Wrap|Line Numbers
  1. = ([Maximum Capacity] = 1)
Hope this hepps!
4 Weeks Ago #2

NeoPa
Expert Mod 15k+
P: 31,170
Perfect answer. Correct and succinct.
4 Weeks Ago #3

Seth Schrock
Expert 2.5K+
P: 2,911
You might want to look at the documentation for the IIF() function as well since it seems that you don't have a very good grasp on it. In this case, TwinnyFo is correct on the best option, but there are times when the IIF() function should be used (like if you wanted to return values other than True/False, like "Full/Empty"). MS Access IIF Function.

So the syntax for your problem would be
Expand|Select|Wrap|Line Numbers
  1. =IIF([Maximum Capacity] = 1, True, False)
This is another way to skin your particular cat, but again, TwinnyFo's method is better because it is more succinct. I just share this for your educational benefit.
4 Weeks Ago #4

twinnyfo
Expert Mod 2.5K+
P: 2,780
Seth,

As a side note, if we are simply talking about proper syntax for the IIf() function, your solution is very correct. Even more so, if the TruePart and FalsePart arguments were anything other than "True" and "False", your solution would not only be correct, but also the best (or only) solution.

However, there is a specific reason I did not include the IIf() function in the solution. OP needs something to resolve to either True or False, with no other options. Using IIf(), the function asks, "What do you want me to return if something is True? If it's not True, then what do you want me to return?" So, the statement [Maximum Capacity] = 1 already resolves to True. From a programming perspective, why would we add any additional conditions and content, when we already have our answer?

Now, if the OP wanted the result to resolve to either "Blue" or "Green", then my solution makes no sense, and addressing the syntactical issue with the IIf() function is the correct means of resolving the issue.

Please don't take this response as a "nit-pick" of your comment--you do well to point out the syntactical error in the original code. However, I did want to point out (particularly to others who might be reading this thread) that there is a reason for writing the solution as I did.

I think I learned these logical tricks from someone here on Bytes. Not sure if NeoPa recalls him or not....

;-)
4 Weeks Ago #5

Seth Schrock
Expert 2.5K+
P: 2,911
Indeed. I did a quick search to see if I could find a website that gave a simple explanation of why your method worked, but I couldn't find one. I normally forget about the choice of your option. The only reason I posted at all was to help the tam21 understand the syntax for the future.
4 Weeks Ago #6

NeoPa
Expert Mod 15k+
P: 31,170
TwinnyFo:
I think I learned these logical tricks from someone here on Bytes. Not sure if NeoPa recalls him or not....

;-)
In answer to the question behind your comment - Of course I both remember guiding you on this as well as - Yes, I'm monitoring all you post too, at least in the Access forum.
@Seth.
As a general rule people need very little help understanding IIf() and its usage. What is less obvious is returning the value from a simple logical statement. Twinny has already explained why that is often preferable to using more complicated syntax but if you need more then I remember explaining this more fully in a thread that Twinny was involved in. It was hard to find so I did it for you - Booleans and Conditional Code.
4 Weeks Ago #7

Seth Schrock
Expert 2.5K+
P: 2,911
Normally I would agree that people understand the IIF() function pretty well, but in this case, the OP seemed to lack that understanding, hence my sharing the corrected version.

Thanks for the link. I didn't need it for my own understanding, but was going to share it for tam21 to understand why it worked. Hopefully, understanding both methods would allow the tam21 to appropriately choose the best method in the future. I will also keep the link for future reference if a post needs that kind of description.
4 Weeks Ago #8

NeoPa
Expert Mod 15k+
P: 31,170
Righto. That all sounds good. I see why you gave the IIf() assistance ;-)
4 Weeks Ago #9

Post your reply

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