Solved

Setting the Rowsource of a List Box with a Stored Procedure and Parameter from code

Posted on 2004-08-19
3
473 Views
Last Modified: 2008-03-17
I am using  an Access 2003 Project (.ADP). On a form I have an Unbound List Box (lstEmployee) and a unbound text box (txtSearch).  I want the user to be able type in a partial name in the txtSearch field and then in the AfterUpdate Event procedure needs to fire off code to set the rowsource to the stored procedure (sp_GetEmployee) along with the parameter from the txtSearch textbox

CREATE PROCEDURE sp_GetEmployee
@Employee varchar(25)
AS
SELECT *
FROM vwEmployeeList
WHERE EmployeeName Like @Employee
GO
0
Comment
Question by:jfrenzley
  • 2
3 Comments
 
LVL 50

Accepted Solution

by:
Steve Bink earned 125 total points
ID: 11842694
Wouldn't it be easier to remove the SP and set the row source directly?

Private Sub txtSearch_AfterUpdate()

lstEmployee.RowSource = "SELECT * FROM vwEmployeeList WHERE EmployeeName Like '%" & txtSearch & "%'"
lstEmployee.Requery

End Sub
0
 

Author Comment

by:jfrenzley
ID: 11843287
Well my understanding is that stored procedures run faster and are ran on the server side.  Network bandwith is an issue.  By using a view directly will it just send the result set or does it send everything?

0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 11871114
Any query you send to a remote server will always return only the result set.  The key is to limit the results to what you need.  For example, opening a table in datasheet view is the same as running the query:

SELECT * FROM MyTable

Running this as an SP on the server, you will not likely see any appreciable speed increase, and the returned results will be the same no matter which method you use.  In fact, using an SP or pass-through query for something simple like this may actually INCREASE the execution time by a small margin.  SPs and pass-through queries are generally meant for those programming items that will have A LOT of execution overhead, or are so complicated that it takes a beast of a machine to wade through.  If there is one universal piece of programming advice, it must be the mantra of KISS...Keep It Simple (Insert Preferred Slur Here).
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question