Solved Passing variable to SQL Server (1 Viewer)

adhoustonj

Member
Local time
Today, 00:12
Joined
Sep 23, 2022
Messages
150
Hello AWF,
What is the best way to pass a hidden text box value to a sql server view?
I have a hidden text box on one of my forms that holds the department an employee belongs to.

This is how I have done it in access.

Code:
SELECT tblEmployees.emp_id, tblEmployees.department
FROM tblEmployees
WHERE tblEmployees.department=[Forms]![frmHomePage]![department]


Thanks
 

theDBguy

I’m here to help
Staff member
Local time
, 21:12
Joined
Oct 29, 2018
Messages
21,484
One way is to use a stored procedure. Another is to use a passthrough query where you modify the SQL statement in code before sending it. Not sure which would be the "best" one for you.
 

adhoustonj

Member
Local time
Today, 00:12
Joined
Sep 23, 2022
Messages
150
One way is to use a stored procedure. Another is to use a passthrough query where you modify the SQL statement in code before sending it. Not sure which would be the "best" one for you.

Thank you - the pass through query sounds like what I need. The terminology will help me dig into this some more.
 

Minty

AWF VIP
Local time
Today, 05:12
Joined
Jul 26, 2013
Messages
10,371
You can also use the same technique on the view from Access assuming you have linked to it.
This is a perfectly valid Access query
Code:
SELECT YourView.emp_id, YourView.department
FROM YourView
WHERE YourView.department=[Forms]![frmHomePage]![department]
 

adhoustonj

Member
Local time
Today, 00:12
Joined
Sep 23, 2022
Messages
150
You can also use the same technique on the view from Access assuming you have linked to it.
This is a perfectly valid Access query
Code:
SELECT YourView.emp_id, YourView.department
FROM YourView
WHERE YourView.department=[Forms]![frmHomePage]![department]

Sweet. Will this process the filter in SQL server or will it send all of the data in the view to my local access FE and then apply the filter?
That is what I meant with "best way" - I should really start drinking coffee again.
 

Minty

AWF VIP
Local time
Today, 05:12
Joined
Jul 26, 2013
Messages
10,371
Access should evaluate the form reference and simply send it as a normal where query to the Server.

You can easily test the efficiency yourself. Create a hard-coded version and the form reference version.
Load the saved queries into a recordset and do a rs.movelast, rs.movefirst with a timer on them in VBA and see if there is a noticeable difference.
 

Users who are viewing this thread

Top Bottom