Solved

Access Query linked Form Dropdown options

Posted on 2014-01-10
7
268 Views
Last Modified: 2014-01-29
Hi all,

I have the following query. Linked to a form dropdown box.
The user is to make a selection on the Main form which will feed the query and run a report.

Selection for tblItems.Itemstatus2 are: Option1, Option2, Option3, All.

I would like the query to show all data for tblItems.Itemstatus2 = All.

"All" is not a value in the field it's an option on the form. However I don't know how to translated for the query.

Your help will be greatly appreciated.

Many thanks,
dnt

Query:

SELECT u.ItemUpdate, u.*, q2.*
FROM tblItemsUpdates AS u INNER JOIN (SELECT tblItems.*, q.MaxOfDateofUpdate FROM tblItems INNER JOIN (SELECT tblItemsUpdates.ItemID, MAX(tblItemsUpdates.DateOfUpdate) AS MaxOfDateofUpdate FROM tblItemsUpdates GROUP BY tblItemsUpdates.ItemID)  AS q ON q.ItemID = tblItems.ItemID WHERE tblItems.Itemstatus2 =[Forms]![Main]![Combo60]  AND tblItems.BusinessChannel =[Forms]![Main]![Combo57])  AS q2 ON (u.ItemID = q2.ItemID) AND (u.DateOfUpdate = q2.MaxOfDateofUpdate)
ORDER BY q2.BusinessChannel, q2.ItemCategory;
0
Comment
Question by:dnt2009
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39770641
Try changing the criteria to this:

 tblItems.Itemstatus2 LIKE iif("" &  [Forms]![Main]![Combo60] = "ALL", "*",  [Forms]![Main]![Combo60])

ie:
SELECT u.ItemUpdate, u.*, q2.*
FROM tblItemsUpdates AS u INNER JOIN (SELECT tblItems.*, q.MaxOfDateofUpdate FROM tblItems INNER JOIN (SELECT tblItemsUpdates.ItemID, MAX(tblItemsUpdates.DateOfUpdate) AS MaxOfDateofUpdate FROM tblItemsUpdates GROUP BY tblItemsUpdates.ItemID)  AS q ON q.ItemID = tblItems.ItemID WHERE tblItems.Itemstatus2 LIKE iif("" &  [Forms]![Main]![Combo60] = "ALL", "*",  [Forms]![Main]![Combo60])  AND tblItems.BusinessChannel =[Forms]![Main]![Combo57])  AS q2 ON (u.ItemID = q2.ItemID) AND (u.DateOfUpdate = q2.MaxOfDateofUpdate)
ORDER BY q2.BusinessChannel, q2.ItemCategory;

Open in new window

0
 
LVL 30

Expert Comment

by:hnasr
ID: 39770714
Compare with this:
Table: a(aid, ...)
Form: _tutorial
ComboBox: cboBox1, displaying a.aid values plus All.

SELECT a.aid from a, ...
where aid like Switch(forms![_tutorial].cboBox1="All","*",forms![_tutorial].cboBox1<>"All",forms![_tutorial].cboBox1);

Open in new window

0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39770742
I prefer to use something along the lines of:
SELECT u.ItemUpdate, u.*, q2.*
FROM tblItemsUpdates AS u 
INNER JOIN (
SELECT tblItems.*
     , q.MaxOfDateofUpdate 
FROM tblItems 
INNER JOIN (
SELECT tblItemsUpdates.ItemID
     , MAX(tblItemsUpdates.DateOfUpdate) AS MaxOfDateofUpdate 
FROM tblItemsUpdates 
GROUP BY tblItemsUpdates.ItemID)  AS q 
ON q.ItemID = tblItems.ItemID 
WHERE (tblItems.Itemstatus2 =[Forms]![Main]![Combo60]  
OR [Forms]![Main]![Combo60] = "ALL")
AND tblItems.BusinessChannel =[Forms]![Main]![Combo57])  AS q2
ON (u.ItemID = q2.ItemID) AND (u.DateOfUpdate = q2.MaxOfDateofUpdate)
ORDER BY q2.BusinessChannel, q2.ItemCategory; 

Open in new window

I added the left paren  on line 13 and all of line 14)
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 30

Expert Comment

by:hnasr
ID: 39770927
fyed,

I like this idea,
>WHERE (tblItems.Itemstatus2 =[Forms]![Main]![Combo60] OR [Forms]![Main]![Combo60] = "ALL")      
But may not work if comparing with numeric field. Did you check that?
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39771028
hnasr,

Good point.  If the bound column is not the text value, then I generally associate a zero with the "All" option.  In that case, I generally use:
OR [Forms]![Main]![Combo60] = 0)

Open in new window

0
 

Author Comment

by:dnt2009
ID: 39779540
Hi all.

Thank you for all your suggestions!
I went with the first one by mbizup and it works perfectly.

Many thanks to all again!
0
 

Author Comment

by:dnt2009
ID: 39794016
What code can I had to the above query when no value is selected from the drop-down to showw all data?

Thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now