473,473 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Select Open, Closed or All

sbouley7
6 New Member
I have a Work Order table containing "Date_Opened" and "Date_Closed" fields amongst other data. I have a query that populates a subform with data from the Work Orders table based on the value of an option group on the main form.
The query contains a calculated field Called "Open" that contains the following
Expand|Select|Wrap|Line Numbers
  1.  Open: IIf(IsNull([tbl_Work_Orders]![DATE_CLOSED]),1,2) 
to report the status of the work order. The "Open" calculated field also contains a criteria that checks the value of the option group in the parent form and Returns: Open Work Orders if the Option Group value is 1; Closed Work Orders if the value is 2; and all records if the value is anything other than 1 or 2. I’ve tried several different expressions and can get values 1 and 2 to work but cannot get it to return all records. The current expression is
Expand|Select|Wrap|Line Numbers
  1.  IIf(Forms![frm_Work_Order_Main]![optgrp_Show_Recs]=1, 1, IIf(Forms![frm_Work_Order_Main]![optgrp_Show_Recs]=2,2, “*”)) 
. 1 returns “Open” records as expected; 2 returns “Closed” records as expected; but 3 returns an error stating the expression is too complex.
Specific help would be greatly appreciated as my knowledge of expressions is limited.

Thank you!!!
Nov 28 '15 #1

✓ answered by jforbes

You could do something like this:
Expand|Select|Wrap|Line Numbers
  1. ...
  2. WHERE ([tbl_Work_Orders]![DATE_CLOSED] IS NULL AND [Forms]![frm_Work_Order_Main]![optgrp_Show_Recs]=1)
  3. OR ([tbl_Work_Orders]![DATE_CLOSED] IS NOT NULL AND [Forms]![frm_Work_Order_Main]![optgrp_Show_Recs]=2)
  4. OR [Forms]![frm_Work_Order_Main]![optgrp_Show_Recs]>2
You may need to tweak it a little, but the idea it to break it up into smaller pieces and OR the conditions together. The last part of the OR evaluates to true and returns all the records when that Option is selected on the Form.

7 943
jforbes
1,107 Recognized Expert Top Contributor
There are a couple ways to approach this and the best way would mostly depend on how you are using your second iif(). If you could post the SQL for the Query, we can knock this one out for you.

To get to the SQL of a Query while it's being edited in Access, click on Dropdown for View on the Ribbon and select SQL. You can then copy the text onto the clipboard and post it here.
Nov 28 '15 #2
zmbd
5,501 Recognized Expert Moderator Expert
when you post the SQL here.
Please select the pasted text and use the [CODE/] format tool to properly paste the required formatting.
(See our FAQ section)

Also, sometimes it is easier to open the query in design mode, then right-click in a blank area of the table view pane and then select the SQL-View from the quick-menu.
Nov 28 '15 #3
sbouley7
6 New Member
jforbes and zmbd, thanks for your replies. I made a few attempts after my post so the SQL is a bit different but the ojective remains the same. With the following SQL statement, I get Open Work Orders when 1 is selected, Closed Work Orders when 2 is selected but nothing when 3 is selected.

Expand|Select|Wrap|Line Numbers
  1. SELECT tbl_Work_Orders.WO_ID, tbl_Work_Orders.TICKET_NUM, tbl_Work_Orders.TICKET_SYSTEM, tbl_Work_Orders.NETWORK, tbl_Work_Orders.SERVICE_ITEM_CAT_ID, tbl_Work_Orders.SERVICE_ITEM_SUB_CAT_ID, tbl_Work_Orders.User, IIf(IsNull([tbl_Hand_Receipts]![HR_Hldr_MI]),[tbl_Hand_Receipts]![HR_Hldr_LName] & ", " & [tbl_Hand_Receipts]![HR_Hldr_FName],[tbl_Hand_Receipts]![HR_Hldr_LName] & ", " & [tbl_Hand_Receipts]![HR_Hldr_FName] & " " & [tbl_Hand_Receipts]![HR_Hldr_MI] & ".") AS Customer, tbl_Work_Orders.REQUEST_DETAILS, tbl_Work_Orders.DATE_OPENED, tbl_Work_Orders.DATE_CLOSED, IIf(IsNull([tbl_Work_Orders]![DATE_CLOSED]),1,2) AS [Open]
  2. FROM tbl_Hand_Receipts INNER JOIN tbl_Work_Orders ON tbl_Hand_Receipts.HR_Num = tbl_Work_Orders.USER
  3. WHERE  (((IIf(IsNull([tbl_Work_Orders]![DATE_CLOSED]),1,2))=IIf([Forms]![frm_Work_Order_Main]![optgrp_Show_Recs]=1,1,IIf([Forms]![frm_Work_Order_Main]![optgrp_Show_Recs]=2,2,(IIf(IsNull([tbl_Work_Orders]![DATE_CLOSED]),1,2)) Like "*"))));
  4.  
Thanks again!
Nov 29 '15 #4
jforbes
1,107 Recognized Expert Top Contributor
You could do something like this:
Expand|Select|Wrap|Line Numbers
  1. ...
  2. WHERE ([tbl_Work_Orders]![DATE_CLOSED] IS NULL AND [Forms]![frm_Work_Order_Main]![optgrp_Show_Recs]=1)
  3. OR ([tbl_Work_Orders]![DATE_CLOSED] IS NOT NULL AND [Forms]![frm_Work_Order_Main]![optgrp_Show_Recs]=2)
  4. OR [Forms]![frm_Work_Order_Main]![optgrp_Show_Recs]>2
You may need to tweak it a little, but the idea it to break it up into smaller pieces and OR the conditions together. The last part of the OR evaluates to true and returns all the records when that Option is selected on the Form.
Nov 29 '15 #5
NeoPa
32,556 Recognized Expert Moderator MVP
You're after the following Truth Table if I understand you correctly :

Expand|Select|Wrap|Line Numbers
  1.    Record       Option          Result
  2. True (Open)     1 (Open)        True
  3. True (Open)     2 (Closed)      False
  4. True (Open)     X (Either)      True
  5. False (Closed)  1 (Open)        False
  6. False (Closed)  2 (Closed)      True
  7. False (Closed)  X (Either)      True
I believe the following should work for you efficiently :
Expand|Select|Wrap|Line Numbers
  1. WHERE   ([Forms]![frm_Work_Order_Main]![optgrp_Show_Recs] Not In(1,2))
  2.    OR   IsNull([tbl_Work_Orders]![DATE_CLOSED])<>([Forms]![frm_Work_Order_Main]![optgrp_Show_Recs]=1)
One of the benefits of this approach is that the whole of the first line can be worked out locally and entered into the SQL as a constant, and so can the second part of the second line (After <>).
Nov 29 '15 #6
sbouley7
6 New Member
jforbes and NeoPa,

Thank you both for your replies!!!

I tried both of your recommendations and jforbes work great without any tweaking required whereas NeoPa's recommendations probably needed some tweaking.

jforbes, I understand the logic in your Where statement but would not have thought to approach it like that. So, thank you for the education.
Nov 29 '15 #7
NeoPa
32,556 Recognized Expert Moderator MVP
You're right. I've just noticed that I used the reference you gave in your first post, which is faulty. Any reference to Forms! should be written as [Forms]! from SQL.

I've updated my earlier post to make it easier to test from.
Nov 30 '15 #8

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

Similar topics

0
by: Michael | last post by:
I have a problem forcing files to download. If I select Save the document is saved with no problems. If I select "Open" the document is empty or I get a "File not found" error from the application...
3
by: 1828080783Maxim | last post by:
Hi, How to open HTML combobox by means of JavaScript? -- Regards, Maxim.
1
by: David Perez | last post by:
Hello. I have a problem with my Web Application in VB.NET and aspx pages. I try to open a SaveDialog window, to open or save a document when user clicl on a button, and Internet Explorer prompts...
3
by: CLarkou | last post by:
On a client's machine with Office 97, my access program gives an error "The Expression you entered refers to an object that is closed or doesn't exist" when I am assigning a value in the checkbox....
3
by: Mark.V.Sullivan | last post by:
I have encountered the same problem another posted about several months ago. Unfortunately, there was no result posted on the old thread. I will let the original message text stand and ask if...
0
by: Elliot | last post by:
I am using the following code to launch Sql Server and execute a query: Process.Start("c:\query.sql") where query.sql contains "Select * from Table1" The result is a read only result-set...
4
by: arajunk | last post by:
In Firefox this opens a full size window (maximized) . In IE it opens the partial window requiring user to click restore (upper right) to maximize. What am I missing ? var...
1
gcoaster
by: gcoaster | last post by:
Hello, Access is accessing my patience! how does one filter just one form with a single combo box selection? I have a combo box named "cboCallStatus" unbound Row source type = Value...
3
by: Barry Edmund Wright | last post by:
Hi All, I have an MS Access DB (2003) with frontend on PC (xp) and backend on Server (2003). I can open multiple instances from this PC. I make a duplicate copy of the MS Access DB and put it onto...
3
by: BarbaraB | last post by:
Is there anyway of returning the value of an option group (in access 2003) back to what it was before any entry was made? I frequenty find people are wishing to remove there answer but with an...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
1
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...
0
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.