Solved

Query to exclude value based on form selection

Posted on 2009-05-08
2
182 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
2 Comments
 
LVL 2

Accepted Solution

by:
shoppedude earned 250 total points
Comment Utility
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
Comment Utility
Thanks that worked! That was easy huh? Sometimes the easy things are the hardest to overcome... for me that is. ;)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

772 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

10 Experts available now in Live!

Get 1:1 Help Now