473,811 Members | 3,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Syntax Error in an IF statement

9 New Member
Help!

I am trying to do an If statement but keep getting a "syntax error (comma)" when I try to run it.

Expand|Select|Wrap|Line Numbers
  1.  Expr1: If([Sales_Amount]<21000000,"5 – 20M",If([Sales_Amount] Between 20999999 And 51000000,"21 – 50M",If([Sales_Amount] Between 50999999 And 101000000,"51 – 100M"," "))) 
I am using Access 2000.


In case it isn't clear what I'm trying to do I would like it to return a value - If the sales amount is less than 210000000 return the value of "5 - 20M", if not less than 21000000 then is sales amount between 20999999 and 5100000 then return the value "21 - 50M", and if not then is the value of the sales amount between 50999999 And 101000000 then return a value of "51 – 100M" else leave it blank.

Any assistance is greatly appreciated.
Feb 15 '07 #1
7 4168
Brisokol
4 New Member
I think you want iif not if..

Help!

I am trying to do an If statement but keep getting a "syntax error (comma)" when I try to run it.

Expand|Select|Wrap|Line Numbers
  1.  Expr1: If([Sales_Amount]<21000000,"5 – 20M",If([Sales_Amount] Between 20999999 And 51000000,"21 – 50M",If([Sales_Amount] Between 50999999 And 101000000,"51 – 100M"," "))) 
I am using Access 2000.


In case it isn't clear what I'm trying to do I would like it to return a value - If the sales amount is less than 210000000 return the value of "5 - 20M", if not less than 21000000 then is sales amount between 20999999 and 5100000 then return the value "21 - 50M", and if not then is the value of the sales amount between 50999999 And 101000000 then return a value of "51 – 100M" else leave it blank.

Any assistance is greatly appreciated.
Feb 15 '07 #2
ADezii
8,834 Recognized Expert Expert
Help!

I am trying to do an If statement but keep getting a "syntax error (comma)" when I try to run it.

Expand|Select|Wrap|Line Numbers
  1.  Expr1: If([Sales_Amount]<21000000,"5 – 20M",If([Sales_Amount] Between 20999999 And 51000000,"21 – 50M",If([Sales_Amount] Between 50999999 And 101000000,"51 – 100M"," "))) 
I am using Access 2000.


In case it isn't clear what I'm trying to do I would like it to return a value - If the sales amount is less than 210000000 return the value of "5 - 20M", if not less than 21000000 then is sales amount between 20999999 and 5100000 then return the value "21 - 50M", and if not then is the value of the sales amount between 50999999 And 101000000 then return a value of "51 – 100M" else leave it blank.

Any assistance is greatly appreciated.
I feel as though this would be an easier solution:
Expand|Select|Wrap|Line Numbers
  1. Sales Range: fCalculateSalesRange([Sales])
Where fCalculateSales Range() is:
Expand|Select|Wrap|Line Numbers
  1. Public Function fCalculateSalesRange(MySales) As String
  2.    If MySales >= 50999999 And MySales <= 101000000 Then
  3.       fCalculateSalesAmount = "51 - 100M"
  4.    ElseIf MySales >= 20999999 And MySales <= 51000000 Then
  5.       fCalculateSalesAmount = "21 - 50M"
  6.    ElseIf MySales < 21000000 Then
  7.       fCalculateSalesAmount = "5 - 20M"
  8.    Else
  9.       fCalculateSalesAmount = vbNullString
  10.    End If
  11. End Function
Sample OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Sales                Sales Range
  2. $20,513,456.00        5 - 20M
  3. $30,000,000.00       21 - 50M
  4. $75,000,000.00       51 - 100M
  5. $21,000,000.00       21 - 50M
  6. $51,000,000.00       51 - 100M
  7. $1,230,000,000.00    
Any other questions, feel free to ask.
Feb 15 '07 #3
erajim
9 New Member
Reply to both of you in one.

Have never heard of IIF statement - I will look at that.

As to the other code that looks great, but where do I put the code. usually I would type the expression in the design view window or in the sql view. not sure how to put the VB script into the query. How do I do that?

Thanks both of you for your help!
Feb 15 '07 #4
erajim
9 New Member
Thanks Brisokol! Although the iif did not work for me it did get me to learn about switch function which did work for me! So thanks!
Feb 15 '07 #5
erajim
9 New Member
Thanks ADezii!

I did not get to use your code because while researching the iif function I learned about the switch function which did the trick! I would like to learn how to do it your way. However as I mentioned above, where do I put the code. usually I would type the expression in the design view window or in the sql view. not sure how to put the VB script into the query. How do I do that?

Thanks you for your help!
Jim
Feb 15 '07 #6
NeoPa
32,579 Recognized Expert Moderator MVP
Thanks ADezii!

I did not get to use your code because while researching the iif function I learned about the switch function which did the trick! I would like to learn how to do it your way. However as I mentioned above, where do I put the code. usually I would type the expression in the design view window or in the sql view. not sure how to put the VB script into the query. How do I do that?

Thanks you for your help!
Jim
Nice to reply to all assistance :)
To use code (VBA) you need to create a module (Alt-F11 from Access; Insert / Module).
Type the code in here then compile and close. This function will then be available to all code (including within SQL) in your project.
HTH.
Feb 15 '07 #7
NeoPa
32,579 Recognized Expert Moderator MVP
IIf() is a very important function in SQL.
Switch() is very useful (especially in this case) but one of my favourites is Choose().
Choose(index, choice-1[, choice-2, ... [, choice-n]])

The Choose function syntax has these parts:
Part Description
index Required. Numeric expression or field that results in a value between 1 and the number of available choices.
choice Required. Variant expression containing one of the possible choices.
Feb 15 '07 #8

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

Similar topics

3
6232
by: Robert Mark Bram | last post by:
Hi All! I have the following two methods in an asp/jscript page - my problem is that without the update statement there is no error, but with the update statement I get the following error: Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80004005) Syntax error in UPDATE statement. /polyprint/dataEntry.asp, line 158
29
2477
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules" for when and how to use single quotes and double quotes in ASP? thanks! ---------------------- SQL = SQL & "WHERE '" & REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE("GenKTitles.
7
248490
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a particular surname in a particular town. I can select the records fine with this syntax (testing in Oracle SQL* Plus) SELECT NAMEINFO.LASTNAME, NAMEINFO.FIRSTNAME, NAMEINFO.MIDDLENAME, NAMEINFO.GENDER, ADDRESSINFO.REGION FROM NAMEINFO, ADDRESSINFO...
7
6682
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double checked, and the insert works fine (tried to use it from access)... im using visual C# express 2k5... what could be wrong? thanks!
3
2502
by: Nathan Sokalski | last post by:
When trying to submit data to an Access database using ASP.NET I recieve the following error: System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
1
3095
by: amitbadgi | last post by:
HI i am getting the foll error while conv an asp application to asp.net Exception Details: System.Runtime.InteropServices.COMException: Syntax error in UPDATE statement. Source Error: Line 112: MM_editCmd.ActiveConnection = MM_editConnection Line 113: MM_editCmd.CommandText = MM_editQuery Line 114: MM_editCmd.Execute
5
2148
by: amitbadgi | last post by:
Hi guys, I am getting the following error in teh insert statement , I am converting this asp application to asp.net, here is teh error, Exception Details: System.Runtime.InteropServices.COMException: Syntax error in INSERT INTO statement. Source Error: Line 118: MM_editCmd.ActiveConnection = MM_editConnection
7
1881
by: Csaba Gabor | last post by:
I feel like it's the twilight zone here as several seemingly trivial questions are bugging me. The first of the following three lines is a syntax error, while the last one is the only one that shows the alert. What is the essential reason? function () { alert('hi mom'); }(); function () { alert('hi dad'); }(8); var x=function () { alert('hi bro'); }();
12
1708
by: Brad Baker | last post by:
I am trying to write a simple ASP.net/C# page which allows users to select some values and produce a report based on a SQL query. I have a self posting dropdown form which allows users to select the type of report to generate: Select the type of report to display: <form runat="server"> <asp:DropDownList AutoPostBack="true" ID="report" runat="server"> <asp:listitem>Report Type 1</asp:listitem>
1
3376
by: ajos | last post by:
hi evrybdy, the problem is:- i had this running before in jsp but when i changed the jsp page using struts tags there occoured a problem... when i enter values in the 2 text boxes and click enter an exception occours which is- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request.
0
9727
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10647
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.