Home   Fees/Services   Access Templates   Tutorials   Tutorial Downloads   Articles   Search   Contact  Privacy  Links
Access Query Criteria Arguments
Criteria Form Field
Home > Tutorials > Query Tutorials > Parameter Query
 






Query Tutorials Index:
Too Complex Query
Aggregate Query
Not In Operator
Choose Function
Crosstab Query
Date Time Query
SQL Delete Query
External Table Query
Report Filter Query
Group By Query
Having Query Clause
Histogram Query
Access Append Query
Master Detail Update
Order By Query
SQL Parameter Query
Predicate Query
Self Join Query
Scalar SubQuery
Master Detail Query
Select Query
Access SQL Select Top
SQL Union Query
SQL Update Query
Custom Query Function

 

MultiSelect Parameter Forms Access Tutorial


Parameter Queries in Microsoft Access

Query Criteria Examples

Access Parameter Query example is an extension of the bottom-up query example.  The form field is used in the query to determine how far to look back in the M_Attendance table for missed work days.



Microsoft Access is a fully capable database and it's primary limitations is the number of concurrent users it will support. Generally, we recommend a limit of 10 to 15 users.

We create databases large and small. Some of our databases help run entire small businesses. We also handle unique businesses such as flyrod manufacturing, cheese making, marina management, and cable tv inventory.


Also, you are running this criteria query from a form called F_Emp_Report. Follow our SQL parameter criteria code example:

Select M_Employees.Name, M_Employees.Emp_Number
From M_Employees
Where M_Employees.Employee_ID in
(Select Employee_ID from M_Attendance
Where M_Attendance.Attendance_Date >= Forms!F_Emp_Report!Start_Date
Group By Employee_ID
Having Count(M_Attendance.Day_Missed) >= 5);

Note:  If you get a Microsoft Access error saying that the form or field Forms![F_Emp_Report]!Start_Date (the criteria field) cannot be found then you need to get the latest update for Access.  Referencing a form when using an aggregate function (like count, max, min, and avg) produces this error when using form fields for query parameters.

Send Values to Access SQL Queries:

Use global variables as query criteria parameters. The setup is as follows:  Make a Module with the following code:

Option Compare Database

Global GBL_Project_ID As Long
Global GBL_Start_Date As Date
Global GBL_End_Date As Date

Option Explicit

Public Function get_global(G_name as string)
    ' determine query criteria values
     Select Case G_name
            Case "Project_ID"
                    Get_Global=GBL_Project_ID
            Case "Start_Date"
                    Get_Global=GBL_Start_Date
            Case "End_Date"
                    Get_Global=GBL_End_Date
    End Select
End Sub

In the form that causes the query (or report) to run, set the global variable in an on-click event of a button.  In the example below the user has select a project from a combo box so we save the project_id in our global variable.

GBL_Project_ID=Project_Combo

In our query, we use the Get_Global function to pass the selected project_ID criteria to the query:

Select Project_ID, Project_Name from M_Projects
Where Project_ID=Get_Global('Project_ID');

More References for Using Access Query Criteria Parameters

Global Variables as Parameters

Visual Basic Global Variables in Query Criteria

Access Query Examples SQL
 







A Blue Claw Software Design Template:

Loan Process Management Access Database
 









A Blue Claw Database Design Article:

Microsoft Access On The Internet
 









Blue Claw Database Design Downloadable Tutorial:
Union Query (Advanced) Access Tutorial Download  








Microsoft Office:
MS Access 2000 Through Access 2016 & Office 365
 


Contact Information
Copyright 2000-2017 Blue Claw Database Design
Development in Microsoft Access, Microsoft SQL/Server and Azure

See our SQL/Server Development and Access Migration Tutorials