Solved

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

Posted on 2004-08-19
3
465 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now