Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Query to exclude value based on form selection

Posted on 2009-05-08
2
Medium Priority
?
206 Views
Last Modified: 2012-05-06
I have an Access 2003 database with a basic query that pulls parameters from a form. I want to exclude the last parameter of the WHERE clause (L.LicensedById = Forms!frmApplicationsTotal!LicensedBy) if the value passed to it is 0. The column that holds the values is an integer and will contain a 1 or 2. Basically if the user doesn't select a value (1 or 2) then I want to return all results whether its a 1 or a 2.

Query below:
SELECT
     Count(*) AS Total
FROM
     dbo_tblApplications AS A
INNER JOIN
     dbo_tblLicense AS L ON A.CredentialID=L.LicenseID
WHERE
     (A.DateReceived>=Forms!frmApplicationsTotal!FromDate And A.DateReceived<=Forms!frmApplicationsTotal!ToDate)
     And (L.LicenseTypeID=Forms!frmApplicationsTotal!LicenseType)
     And (A.ApplicationType=Forms!frmApplicationsTotal!ApplicationType)
     And (L.LicensedById = Forms!frmApplicationsTotal!LicensedBy);

Open in new window

0
Comment
Question by:adamch25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
shoppedude earned 1000 total points
ID: 24339061
I believe this should work for you:


SELECT
     Count(*) AS Total
FROM
     dbo_tblApplications AS A
INNER JOIN
     dbo_tblLicense AS L ON A.CredentialID=L.LicenseID
WHERE
     (A.DateReceived>=Forms!frmApplicationsTotal!FromDate And A.DateReceived<=Forms!frmApplicationsTotal!ToDate)
     And (L.LicenseTypeID=Forms!frmApplicationsTotal!LicenseType)
     And (A.ApplicationType=Forms!frmApplicationsTotal!ApplicationType)
     And (Forms!frmApplicationsTotal!LicensedBy = 0 
      Or (Forms!frmApplicationsTotal!LicensedBy <> 0 And L.LicensedById = Forms!frmApplicationsTotal!LicensedBy))

Open in new window

0
 

Author Closing Comment

by:adamch25
ID: 31579580
Thanks that worked! That was easy huh? Sometimes the easy things are the hardest to overcome... for me that is. ;)
0

Featured Post

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

715 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