Query using date range and another input (1 Viewer)

Poco_90

Registered User.
Local time
Today, 09:22
Joined
Jul 26, 2013
Messages
87
Hi,
I have a query that is wrecking my head, it is the format of my query that is my problem. I have a form that a users has an option to select a trainee name and filter the data, now I want to add a start and end date, sounds easy but no matter what I try, my query is showing all the results or none of the results. I would like the option that if no dates were selected, all records would show. Below is my code. I have tried all combinations of AND or OR but have had no luck. Should I be going about this in a different way?
Thanks in advance,
Poco

Code:
SELECT tblTrainingRecords.Trainee.Value, tblTrainingRecords.Trainer, tblTrainingRecords.TrainingDescription, tblTrainingRecords.Comments, tblTrainingRecords.AreaOfTraining, tblTrainingRecords.TrainingDate, tblTrainingRecords.ID, tblTrainingRecords.TraineeHours, tblTrainee.Trainee
FROM tblTrainee INNER JOIN tblTrainingRecords ON tblTrainee.ID = tblTrainingRecords.Trainee.Value
WHERE (((tblTrainingRecords.Trainee.Value)=Forms!frmTrainee!cboTrainee) OR ((tblTrainingRecords.TrainingDate)>=Forms!frmTrainee!cboStartDate And (tblTrainingRecords.TrainingDate)<=Forms!frmTrainee!cboEndDate)) Or (((Forms!frmTrainee!cboTrainee) Is Null));
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 18:22
Joined
Jan 20, 2009
Messages
12,861
Make sure you bracketing is correct. Deleting the pointless plethora of excess brackets inserted by Access often helps.

Be aware of the operator precedence. Unless defined by brackets, AND is processed before OR.

It is easier to read using BETWEEN than greater than and less than conditions.
 

Users who are viewing this thread

Top Bottom