Criteria (1 Viewer)

mike60smart

Registered User.
Local time
Today, 09:41
Joined
Aug 6, 2017
Messages
1,908
Hi Everyone

The following query works as it should:-

Code:
SELECT qryInspectionsDue.FleetID, qryInspectionsDue.Employee, qryInspectionsDue.InspectionDate, qryInspectionsDue.Mileage, qryInspectionsDue.DueDate, qryInspectionsDue.DueRenewal, qryInspectionsDue.DueYear, qryInspectionsDue.Months
FROM qryInspectionsDue
WHERE (((qryInspectionsDue.DueYear)=[Enter Year Required]) AND ((qryInspectionsDue.Months) Between [Start Month] And [End Month]));

Why does the following not work?

txtStartMonth , txtEndMonth & txtYear are all unbound Combobox's with a Command Button to open the Report.

Code:
SELECT qryInspectionsDue.FleetID, qryInspectionsDue.Employee, qryInspectionsDue.InspectionDate, qryInspectionsDue.Mileage, qryInspectionsDue.DueDate, qryInspectionsDue.DueRenewal, qryInspectionsDue.DueYear, qryInspectionsDue.Months
FROM qryInspectionsDue
WHERE (((qryInspectionsDue.DueYear)=[forms]![frmFleetReports]![txtYear]) AND ((([qryInspectionsDue].[Months])>=[Forms]![frmFleetReports]![txtStartMonth])<=[Forms]![frmFleetReports]![txtEndMonth]));

Any Help appreciated
 

bob fitz

AWF VIP
Local time
Today, 09:41
Joined
May 23, 2011
Messages
4,718
Is the form called "frmFleetReports" open.
 

bob fitz

AWF VIP
Local time
Today, 09:41
Joined
May 23, 2011
Messages
4,718
On closer inspection, I think you're missing an "AND" from the WHERE statement.
Try:
Code:
SELECT qryInspectionsDue.FleetID, qryInspectionsDue.Employee, qryInspectionsDue.InspectionDate, qryInspectionsDue.Mileage, qryInspectionsDue.DueDate, qryInspectionsDue.DueRenewal, qryInspectionsDue.DueYear, qryInspectionsDue.Months
FROM qryInspectionsDue
WHERE (((qryInspectionsDue.DueYear)=[forms]![frmFleetReports]![txtYear]) AND ((([qryInspectionsDue].[Months])>=[Forms]![frmFleetReports]![txtStartMonth]) [COLOR="Red"]AND[/COLOR] <=[Forms]![frmFleetReports]![txtEndMonth]));
 

mike60smart

Registered User.
Local time
Today, 09:41
Joined
Aug 6, 2017
Messages
1,908
Hi Bob

That gives me the following error
 

Attachments

  • error.PNG
    error.PNG
    6.7 KB · Views: 80

jdraw

Super Moderator
Staff member
Local time
Today, 04:41
Joined
Jan 23, 2006
Messages
15,379
How about
Code:
SELECT qryInspectionsDue.FleetID
	,qryInspectionsDue.Employee
	,qryInspectionsDue.InspectionDate
	,qryInspectionsDue.Mileage
	,qryInspectionsDue.DueDate
	,qryInspectionsDue.DueRenewal
	,qryInspectionsDue.DueYear
	,qryInspectionsDue.Months
FROM qryInspectionsDue
WHERE ((qryInspectionsDue.DueYear) = [forms]![frmFleetReports]![txtYear])
	AND (
		([qryInspectionsDue].[Months]) BETWEEN [Forms]![frmFleetReports]![txtStartMonth]
			AND [Forms]![frmFleetReports]![txtEndMonth]
		);
 

jdraw

Super Moderator
Staff member
Local time
Today, 04:41
Joined
Jan 23, 2006
Messages
15,379
Happy to help. Glad it's working.
 

Users who are viewing this thread

Top Bottom