Please try this (I cannot test your SQL statement without seeing your tables, make sure it works). The code assumes that you have at least one SQL server linked table in your current db that you can use to get the connection string needed for the new query; if you do not have have you have to create a valid connection string to access your SQL database.
Don't confuse pass-through queries (which reside in the Access front-end but are written in the back-end database syntax, in your case SQL Server) with stored procedures which reside in the back-end and can accept parameters as explained by Ranman.
Code:
Sub test()Dim sAssignedName as string
sAssignedName = fnPass_Through(1502, 1, 1)
End Sub
Public Function fnPass_Through(Counter As Integer, Request As Integer, Release As Integer) as String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim qdfPassThrough As DAO.QueryDef
Dim strSql As String
' Modify this line to include the path to Northwind
' on your computer.
'Set dbs = Application.DBEngine(0).Databases(0)
Set dbs=CurrentDB
' Create a named QueryDef based on the SQL statement.
If QueryExists("NewQry") Then dbs.QueryDefs.Delete "NewQry"
Set qdfPassThrough = dbs.CreateQueryDef("NewQry")
strSql = ""
strSql = strSql & "SELECT DISTINCT rdLab.tblEmployee.Assigned_Name, rdLab.tblTestRequests.Counter, rdLab.tblTestRequests.Project_Request, rdLab.tblTestRequests.Project_Release"
strSql = strSql & " FROM rdLab.tblAssignedPerson_Link INNER JOIN"
strSql = strSql & " rdLab.tblEmployee ON rdLab.tblAssignedPerson_Link.APL_Link_Person = rdLab.tblEmployee.Employee_ID INNER JOIN"
strSql = strSql & " rdLab.tblTestRequests ON rdLab.tblAssignedPerson_Link.APL_Link_Counter = rdLab.tblTestRequests.Counter"
strSql = strSql & " WHERE (rdLab.tblTestRequests.Counter = " & Counter & ") And (rdLab.tblTestRequests.Project_Request = " & Request & ") And (rdLab.tblTestRequests.Project_Release = " & Release & ")"
strSql = strSql & " ORDER BY rdLab.tblEmployee.Assigned_Name"
qdfPassThrough.Connect= dbs.TableDefs("tblOneOfSQLServerLinkedTables").Connect ' you need to set the connection string for the new query
qdfPassThrough.SQL=strSql 'Set the SQL property of the pass-through query to the one you just built
qdfPassThrough.ReturnsRecords=True
' Create a temporary snapshot-type Recordset.
Set rst = qdfPassThrough.OpenRecordset(dbOpenSnapshot)
' Populate the Recordset.
'rst.MoveLast
if rst.RecordCount=0 then GoTo Exit_fnPass_Through 'the pass-through returned no records
fnPass_Through=rst("Assigned_Name")
Exit_fnPass_Through:
dbs.QueryDefs.Delete "NewQry"
Set rst=nothing
Set qdf=Nothing
dbs.Close
Set dbs=Nothing
End Function
Function QueryExists(strQueryName As String) As Boolean
Dim qdfLoop As DAO.QueryDef
For Each qdfLoop In CurrentDb.QueryDefs
If strQueryName = qdfLoop.Name Then
'Debug.Print Now, "[QueryExists] Query '" & strQueryName & "' exists"
QueryExists = True
Exit For
End If
Next qdfLoop
End Function
Cheers,