Help!
I am trying to do an If statement but keep getting a "syntax error (comma)" when I try to run it. - 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.
7 4149
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. - 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.
Help!
I am trying to do an If statement but keep getting a "syntax error (comma)" when I try to run it. - 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: - Sales Range: fCalculateSalesRange([Sales])
Where fCalculateSalesRange() is: - Public Function fCalculateSalesRange(MySales) As String
-
If MySales >= 50999999 And MySales <= 101000000 Then
-
fCalculateSalesAmount = "51 - 100M"
-
ElseIf MySales >= 20999999 And MySales <= 51000000 Then
-
fCalculateSalesAmount = "21 - 50M"
-
ElseIf MySales < 21000000 Then
-
fCalculateSalesAmount = "5 - 20M"
-
Else
-
fCalculateSalesAmount = vbNullString
-
End If
-
End Function
Sample OUTPUT: - Sales Sales Range
-
$20,513,456.00 5 - 20M
-
$30,000,000.00 21 - 50M
-
$75,000,000.00 51 - 100M
-
$21,000,000.00 21 - 50M
-
$51,000,000.00 51 - 100M
-
$1,230,000,000.00
Any other questions, feel free to ask.
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!
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!
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
NeoPa 32,556
Expert Mod 16PB
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.
NeoPa 32,556
Expert Mod 16PB
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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:
...
|
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"...
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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: 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...
|
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...
| |