473,385 Members | 1,661 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.

Combobox Query Ignoring Blank Fields

mjoachim
I currently have a Combobox that is linked to a table and is designed to limit possible entries based on 2 other form fields. To do this, I am using this query:

Expand|Select|Wrap|Line Numbers
  1. SELECT [Cost Codes].CostCode 
  2. FROM [Cost Codes] 
  3. WHERE ((([Cost Codes].JobNumber)
  4.         =[Forms]![Data Import]![Job Number]) 
  5.     AND (([Cost Codes].SubJobNumber)
  6.         =[Forms]![Data Import]![Sub Job])) 
  7. ORDER BY [Cost Codes].CostCode;
The problem I'm having is that if the Sub Job on the Form is left blank, the query isn't returning anything, rather than the desired filtering to table entries with a matched job number and blank sub job number.

I have tried playing around with Is Null and if placed in the Or portion of the Query Builder, table entries with blank Sub Jobs always appear in the ComboBox.

Any ideas on how to modify this to only show Cost Codes with matching Job and Sub Job numbers, even if the Sub Job field is blank?
Jul 15 '15 #1

✓ answered by jforbes

Typically for something like this, you can add a test for Null/Blank value for the SubJob as part of the Criteria.
Expand|Select|Wrap|Line Numbers
  1. SELECT [Cost Codes].CostCode FROM [Cost Codes]
  2. WHERE [Cost Codes].JobNumber)=[Forms]![Data Import]![Job Number] 
  3. AND ([Cost Codes].SubJobNumber)=[Forms]![Data Import]![Sub Job] OR Nz([Forms]![Data Import]![Sub Job], '')='')
  4. ORDER BY [Cost Codes].CostCode;
The Null/Blank test is ORed with the test for a specific SubJob so either a specific value is returned or all values are returned.

6 2290
jforbes
1,107 Expert 1GB
Typically for something like this, you can add a test for Null/Blank value for the SubJob as part of the Criteria.
Expand|Select|Wrap|Line Numbers
  1. SELECT [Cost Codes].CostCode FROM [Cost Codes]
  2. WHERE [Cost Codes].JobNumber)=[Forms]![Data Import]![Job Number] 
  3. AND ([Cost Codes].SubJobNumber)=[Forms]![Data Import]![Sub Job] OR Nz([Forms]![Data Import]![Sub Job], '')='')
  4. ORDER BY [Cost Codes].CostCode;
The Null/Blank test is ORed with the test for a specific SubJob so either a specific value is returned or all values are returned.
Jul 15 '15 #2
You are correct that attaching the Nz statement on the end does provide all values if the field is left blank.

To clarify what I need though: a blank field is essentially also a value. When the field is left blank, I can't have Cost Code values that belong to Sub Job 100 or 200.

Hopefully that makes more sense now, sorry for the confusion!
Jul 15 '15 #3
zmbd
5,501 Expert Mod 4TB
Essentially, the blank field is not a value which is why the NZ() behaved the way it did for your results.
(MSACC/VBA Insights> What is Null? )

As for what you are wanting for results, I think you need to provide some example data...
Just click on the [CODE/] button in the post toolbar and insert your tabular raw data and your desired results between the sets of "code tags"

You should also look at:
MSACC/VBA Insights> Cascaded Form Filtering - sounds like this is what you are attempting....
Jul 15 '15 #4
Expand|Select|Wrap|Line Numbers
  1. JobNumber SubJobNumber       CostCode
  2. 132401                 0000.000000        
  3. 132401                 0100.010100        
  4. 132401          200     0100.010800        
  5. 132401          200     0300.030700        
  6. 151601          100     0400.040100        
  7. 151601          100     0400.040200        
  8. 151601                 0400.040200        
  9. 151601          100     0400.040225        
  10. 151601          200     0600.060100        
  11. 151601                 0600.060100        
  12. 151601          200     0600.060180        
  13. 152405          100     1000.100300        
  14. 152405                 1000.100400        
  15. 152405                 1100.110100        
  16. 152405          200     1100.110100        
  17. 152405          100     1100.110200        
  18. 152405                 1100.110200        
  19. 152405                 1100.110250        
  20.  
The form has a control for Job Number, Sub Job and Cost Code. Selections for Job Number and Sub Job should limit the combo box options for Cost Code. A Sub Job value of blank should be treated as it's own value unique from other Sub Job's so that if the control is left blank, Cost Codes that belong to Job Number 151601 & Sub Job 100 are not available in the combo box.
Jul 15 '15 #5
jforbes,

To build off your idea, rather than just assigning the form Nz values to "", I also assigned the table Nz values to "" which appears to have worked to provide them with a matchable value.

Expand|Select|Wrap|Line Numbers
  1. SELECT [Cost Codes].CostCode
  2. FROM [Cost Codes]
  3. WHERE ((([Cost Codes].SubJobNumber)=[Forms]![Data Import]![Sub Job]) AND (([Cost Codes].JobNumber)=[Forms]![Data Import]![Job Number])) OR ((([Cost Codes].JobNumber)=[Forms]![Data Import]![Job Number]) AND ((Nz([Cost Codes].[SubJobNumber],""))=Nz([Forms]![Data Import]![Sub Job],"")))
  4. ORDER BY [Cost Codes].CostCode;
  5.  

Thank you for everyone's help!
Jul 15 '15 #6
zmbd
5,501 Expert Mod 4TB
Three controls feeding from each other... follow the cascading filter example.

Test for isnull
WHERE [tbl]![field] is null
or
WHERE Not([tbl]![field]) is null
Jul 15 '15 #7

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

Similar topics

1
by: jj | last post by:
Hi NG I got 2 tables In both of the tables there are 4 indentical fields 1) Road name 2) House number 3) Letter 4) Floor In table one there is an extra field - an Id field. In this table...
1
by: Brian Keanie | last post by:
What would the cretria be in a query to SELECT all the blank fields in a table? Have tried "", "space", etc Thanks
4
by: Sommerfield | last post by:
I've imported a txt list into Access which has some rows that look like: 0000 0100 CH Saze National Msr 1 M CH 4460b 4750x 4800q 5945b 6030b 6125s 7275b 7290b 9500s 9630q 9675b...
1
by: Shiny | last post by:
Hi all, I'm fairly new to Access and SQL. My sense is that my question is fairly basic, but I still need help with it. I have a table with players who are listed either in the fields...
0
by: visionstate | last post by:
Hi there, I have a form which has 2 text boxes, a combo box and a sub form in it (which reads from a query. The query reads from the table). On load, I would like the fields in the text boxes and...
1
by: gautam89 | last post by:
Hi everyone... I'm a high school student working on an Access project for a summer internship. I needed your assistance in writing a criteria for a select query. Table1 has the following...
1
by: just1812 | last post by:
I'm trying to pick off fileds from a line to insert them into a database. The problem that I'm having is that there is no delemiters between columns or set amount of spaces. Some columns have blank...
2
by: Will | last post by:
Hi, I need to handle blank values in a query calculation. I have 636 records at the moment but when I sum over these records the blank fields are not returned. I have looked around here and on...
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
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...
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
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.