Home  Fees/Services  Access Templates  Tutorials  Access Download  Articles  Search  Contact  Privacy  Links

Access Query Examples
MS Access SQL Support & Training
Query Parameter Methods

SQL Parameter Query Example Queries Microsoft Access 2007 Query Help
Professional Microsoft Access Programmers

Access Template Databases:


MS Query Tutorials:

Aggregate Functions
Choose Function
More Choose Functions
Crosstab Query Tutorial
Crosstab Query Advanced
DateTime Query
Delete Query Tutorial
External Link Query
Access Report Filter Query
Group By Clause
Access Having Clause
Histogram Query Tutorial
Insert Into Query
Master/Detail Updates
Order By Dynamic
Access Parameter Query
Predicate Query Example
Self Join Query Tutorial
Scalar Query Example
Child/Parent Table Query
Select Statement Tutorial
Select Top 1 Query
Union Query Example
Access Update Query

Multi-Select Parameter Forms Query Tutorial


Parameter Query in Microsoft Access

Query parameters 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.  Also, you are running this parameter query from a form called F_Emp_Report.

Access Query Parameters 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 an Microsoft Access error saying that the form or field Forms![F_Emp_Report]!Start_Date (the parameter) cannot be found then you need to get the latest update for Access 2000, Version 9.0.4402 SR-1.  Referencing a form when using an aggregate function (like count, max, min, avg) produces this error when using form fields for query parameters.

More Advanced Parameter Query Methods:

Use global variables as query 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)

     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 to the query:

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

More References for Using Access Query Parameters

Global Variables as Parameters

Programming Microsoft Access Visual Basic using global variable to pass parameter to Access queries.
www.blueclaw-db.com/access_pass_parameter_global_variable.htm

Visual Basic Global Variables in Query Parameters

Visual Basic Global Variables as Access Query Parameters. Using global variables to pass user selection criteria to queries is a useful programming technique to ...
www.blueclaw-db.com/download/global_variables_parameters.htm

Access Query Examples SQL

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 ...
www.blueclaw-db.com/accessquerysql/


Contact Information

Microsoft Access Developer

Microsoft Access Query 2007 2003 2000 Access Query Tutorial