Running a stored procedure from an Access project

K

kiloez

What's the best way to run a stored procedure from code in a Access project?
I'm currently passing a string to the rst.open method, using something like
this:

Dim strSSN As String
Dim rst As ADODB.Recordset
Dim strSproc As String

strSSN = InputBox("Please enter SSN to search", "Client Search")

strSproc = "execute dbo.spGetClientBySSN " & "'" & strSSN & "'"

Set rst = New ADODB.Recordset

rst.Open strSproc, CurrentProject.Connection


It works just fine, but I'm wondering if there is a better way.
 
T

Tom van Stiphout

On Mon, 8 Sep 2008 11:35:01 -0700, kiloez

I think it is better to create an ADODB.Command object, and add
Parameters to it representing the sproc arguments. That gives you much
more flexibility, for example if you have an Output parameter.

Also, don't repeatedly create these objects in every function that
needs a recordset, but consolidate common code (e.g.
GetReadonlyRecordset) in a (class) module.

-Tom.
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top