473,385 Members | 1,333 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,385 software developers and data experts.

Function and Nested loop

Table with 3000 records with 21 column fields

I need to loop thru the records using the 2 column fields (Field2 and Field3) where there are a null values to Produced a New column field (Field4) I started with this function below but I am stuck since case select cannot accept null- or I may need to use another way?

SampleTable
Expand|Select|Wrap|Line Numbers
  1. Name     Parts   Categories  New Field
  2. (Field1) (Field2)(Field3)    (Field4)
  3. 1         A1      R1         Inventory
  4. 2         A1      Null       Inventory
  5. 3         B1      R1         Processing
  6. 4         B1      R4         Processing
  7. 5         B1      Null       Unknown 
  8. 6         Null    Null       Unknown
Expand|Select|Wrap|Line Numbers
  1. Function MachineCheck(Field2, Field3) As String
  2.  
  3. Dim newValue As String
  4.  
  5. Select Case (Field2)
  6.      Case "A1":
  7.         Select Case (Field3)
  8.             Case "R1"
  9.                 newValue = "Inventory"
  10.             Case Is null
  11.                 newValue = "Inventory"
  12.             Case "R1"
  13.                 newValue = "Inventory"
  14.             Case “ “
  15.                 newValue = "Inventory"
  16.  
  17.        Select Case (Field2)
  18.          Case “B1”
  19. End Select
  20.  
  21. MachineCheck = newValue
  22. End Function
Query calls this function
Status: MachineCheck ([Field2],[Field3])

Thanks for your help as always!
Jun 26 '16 #1

✓ answered by NeoPa

You cannot compare a value to Null. Null is not a value as such - it is the state where no defined value exists. Thus, X = Null can never make sense.

To use Select Case to include checking for a variable or field being Null you can use :
Expand|Select|Wrap|Line Numbers
  1. Select Case True
  2. Case IsNull(X)
  3.     ...
  4. Case X = "Blah"
  5.     ...
  6. Case X = "Blah blah"
  7.     ...
  8. End Select

5 1436
NeoPa
32,556 Expert Mod 16PB
You cannot compare a value to Null. Null is not a value as such - it is the state where no defined value exists. Thus, X = Null can never make sense.

To use Select Case to include checking for a variable or field being Null you can use :
Expand|Select|Wrap|Line Numbers
  1. Select Case True
  2. Case IsNull(X)
  3.     ...
  4. Case X = "Blah"
  5.     ...
  6. Case X = "Blah blah"
  7.     ...
  8. End Select
Jun 26 '16 #2
NeoPa
32,556 Expert Mod 16PB
I should add that working on your code in a word processor, as opposed to a text editor, is a very bad idea. When posted properly in the [CODE] tags you can easily see why.
Jun 26 '16 #3
Thanks so much for your kindness. I will try to use word processor next time. I am still learning. Thanks for being patient.
Jun 26 '16 #4
zmbd
5,501 Expert Mod 4TB
orchid67 actually, Neopa was suggesting something like Notepad instead of MS-Word or WordPad. :)
The former is a pure ASCII editor whereas the latter two use richtext or other formatting that doesn't pass thru to the post.
For Code, I tend to just use the VBA-Editor, the formatting holds properly when placing the [code] tags. :)
Jun 27 '16 #5
NeoPa
32,556 Expert Mod 16PB
Orchid:
I will try to use word processor next time. I am still learning.
I hope that ZMBD's post has clarified that a little.

In case it's still not clear though, it's the word processors (Like Word and WordPad) that give you the problems. Use a text editor instead for reliable results. Examples of text editors are :
Notepad - Comes with Windows.
Notepad++ - Available for free.
TextPad - Also free. I use this and it does a great job.

I've heard that Notepad++ does a fine job too, but I can't say that from my own experience.
Jun 27 '16 #6

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

Similar topics

25
by: chad | last post by:
I am writing a program to do some reliability calculations that require several nested for-loops. However, I believe that as the models become more complex, the number of required for-loops will...
0
by: John Wilson | last post by:
Hello, I have the following code which populates as table data from a SQL Server 2000 stored proc (RSByDemoID2). Below that is the view and stored procedure which takes @DemoID as input to match...
1
by: mhk | last post by:
Hi, i have a nested loop in Javascript and i have a break statement in inner loop. As break statement takes control come out of inner loop. I want to come out of both loops if break statement...
2
by: smauldin | last post by:
Why does the execution plan have a nested loop join for a simple select with an UDF in the where clause? Here is the query: select * from test_plan where vCol = my_udf('test') Here is the...
5
by: Blankdraw | last post by:
I can't get this nested loop to break the outer loop at the 5th data value so control can proceed to the next array col and continue pigeon-holing the next 5 in its own column. Why can I not get...
2
by: tony collier | last post by:
Hi i want to get a user to input x which then creates an nested loop with x levels. each level of the loop has the same number of iterations e.g. for the case where x=3, the following code is...
1
by: Goldie | last post by:
Can anyone offer advice on how to do a nested loop with vb I need the loop nested in the main loop to be passed a variable from the parent loop for SQL purposes. eg: parent selects all...
4
by: evantri | last post by:
i tried to do this nested loop function double minx = -1.0 double maxx = 1.0 double miny = -1.0 double maxy = 1.0 double x; double y; for (x=minx;x<=maxx;x+0.5)
12
by: upernikaw | last post by:
Hello, I am attempting to create a nested loop (in Access 2003/VB) that will print a report for a set of user defined months inputed on a form and that will print out for every Client. So the first...
8
by: TobbeK | last post by:
Need some help with a nested loop. This one (my example code below) prints out a correct 3 column HTML table with the recordset with proper opening and closing HTML tags AS LONG as the GRUOP BY...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.