PC Review


Reply
Thread Tools Rate Thread

Accessing Stored Procedure via VBA

 
 
Patrick Pohlmann
Guest
Posts: n/a
 
      4th Feb 2010
Hi,

I am trying to work with Stored presucures insted of buliding querys within
vba. I am working with an access .adp (Access 2007) and SQL Server 2005

There are two quesitions I would like to know:

1. How to use a stored procedure with parameters as recordsource for an
access form.
2. How to open a stored procedure via vba to view the results

For example my Prozedure is called: proc_myproc and it need two parameters
like @one und @two.

I would be very happy if someone could tell me how to do this.

Thanks a lot.

Regards

Patrick



 
Reply With Quote
 
 
 
 
Sylvain Lafontaine
Guest
Posts: n/a
 
      4th Feb 2010
You must either build a query string using the EXEC statement (untested):

Dim sql as string
sql = "EXEC MySP 1, 2, 'Sylvain' "
Form.RecordSource = sql

Or you can use the InputParameters property to define each parameters. For
the EXEC statement, you don't need to refresh or requery the form after
changing the record source as this is done automatically. For complex
cases, using the UniqueTable and the ResyncCommand will help you.

This has been explained many times in the past, so you can search this
newsgroup for these keywords. I will try to soon write an article on this
on my blog that I've started two months ago; however, I'm already late for
many weeks on this because I've had to learn things like
Photoshop/GIMP/Paint.Net first.

--
Sylvain Lafontaine, ing.
MVP - Windows Live Platform
Blog/web site: http://coding-paparazzi.sylvainlafontaine.com
Independent consultant and remote programming for Access and SQL-Server
(French)


"Patrick Pohlmann" <(E-Mail Removed)> wrote in message
news:E7A11F31-DF07-40F9-A6FA-(E-Mail Removed)...
> Hi,
>
> I am trying to work with Stored presucures insted of buliding querys
> within vba. I am working with an access .adp (Access 2007) and SQL Server
> 2005
>
> There are two quesitions I would like to know:
>
> 1. How to use a stored procedure with parameters as recordsource for an
> access form.
> 2. How to open a stored procedure via vba to view the results
>
> For example my Prozedure is called: proc_myproc and it need two parameters
> like @one und @two.
>
> I would be very happy if someone could tell me how to do this.
>
> Thanks a lot.
>
> Regards
>
> Patrick
>
>
>



 
Reply With Quote
 
Patrick Pohlmann
Guest
Posts: n/a
 
      5th Feb 2010
Hi Sylvain,

thank you very much. Look quite easy for me. Thanks.

Can you help me with me secound question, too? How can I open a SP as a view
with parameters via VBA. So that the user can see the results?

Thanks again.

Patrick

"Sylvain Lafontaine" <(E-Mail Removed)> schrieb im Newsbeitrag
news:#(E-Mail Removed)...
> You must either build a query string using the EXEC statement (untested):
>
> Dim sql as string
> sql = "EXEC MySP 1, 2, 'Sylvain' "
> Form.RecordSource = sql
>
> Or you can use the InputParameters property to define each parameters.
> For the EXEC statement, you don't need to refresh or requery the form
> after changing the record source as this is done automatically. For
> complex cases, using the UniqueTable and the ResyncCommand will help you.
>
> This has been explained many times in the past, so you can search this
> newsgroup for these keywords. I will try to soon write an article on this
> on my blog that I've started two months ago; however, I'm already late for
> many weeks on this because I've had to learn things like
> Photoshop/GIMP/Paint.Net first.
>
> --
> Sylvain Lafontaine, ing.
> MVP - Windows Live Platform
> Blog/web site: http://coding-paparazzi.sylvainlafontaine.com
> Independent consultant and remote programming for Access and SQL-Server
> (French)
>
>
> "Patrick Pohlmann" <(E-Mail Removed)> wrote in message
> news:E7A11F31-DF07-40F9-A6FA-(E-Mail Removed)...
>> Hi,
>>
>> I am trying to work with Stored presucures insted of buliding querys
>> within vba. I am working with an access .adp (Access 2007) and SQL Server
>> 2005
>>
>> There are two quesitions I would like to know:
>>
>> 1. How to use a stored procedure with parameters as recordsource for an
>> access form.
>> 2. How to open a stored procedure via vba to view the results
>>
>> For example my Prozedure is called: proc_myproc and it need two
>> parameters like @one und @two.
>>
>> I would be very happy if someone could tell me how to do this.
>>
>> Thanks a lot.
>>
>> Regards
>>
>> Patrick
>>
>>
>>

>
>
>

 
Reply With Quote
 
Sylvain Lafontaine
Guest
Posts: n/a
 
      5th Feb 2010
Second question: I have no idea: I always use forms to open even the
simplest SP and provide the required parameters. I remember seen some posts
on this topic but I never give them any real attention.

You can use the Currentproject.Connection.Execute to call a stored procedure
with parameters by using the EXEC call as explained earlier but I don't know
if this can display the result of a query to the user. Search Google for
« currentproject.connection.execute stored procedure EXEC »

--
Sylvain Lafontaine, ing.
MVP - Windows Live Platform
Blog/web site: http://coding-paparazzi.sylvainlafontaine.com
Independent consultant and remote programming for Access and SQL-Server
(French)


"Patrick Pohlmann" <(E-Mail Removed)> wrote in message
news:0693BFE3-DCE0-4C36-A600-(E-Mail Removed)...
> Hi Sylvain,
>
> thank you very much. Look quite easy for me. Thanks.
>
> Can you help me with me secound question, too? How can I open a SP as a
> view with parameters via VBA. So that the user can see the results?
>
> Thanks again.
>
> Patrick
>
> "Sylvain Lafontaine" <(E-Mail Removed)> schrieb im
> Newsbeitrag news:#(E-Mail Removed)...
>> You must either build a query string using the EXEC statement (untested):
>>
>> Dim sql as string
>> sql = "EXEC MySP 1, 2, 'Sylvain' "
>> Form.RecordSource = sql
>>
>> Or you can use the InputParameters property to define each parameters.
>> For the EXEC statement, you don't need to refresh or requery the form
>> after changing the record source as this is done automatically. For
>> complex cases, using the UniqueTable and the ResyncCommand will help you.
>>
>> This has been explained many times in the past, so you can search this
>> newsgroup for these keywords. I will try to soon write an article on
>> this on my blog that I've started two months ago; however, I'm already
>> late for many weeks on this because I've had to learn things like
>> Photoshop/GIMP/Paint.Net first.
>>
>> --
>> Sylvain Lafontaine, ing.
>> MVP - Windows Live Platform
>> Blog/web site: http://coding-paparazzi.sylvainlafontaine.com
>> Independent consultant and remote programming for Access and SQL-Server
>> (French)
>>
>>
>> "Patrick Pohlmann" <(E-Mail Removed)> wrote in message
>> news:E7A11F31-DF07-40F9-A6FA-(E-Mail Removed)...
>>> Hi,
>>>
>>> I am trying to work with Stored presucures insted of buliding querys
>>> within vba. I am working with an access .adp (Access 2007) and SQL
>>> Server 2005
>>>
>>> There are two quesitions I would like to know:
>>>
>>> 1. How to use a stored procedure with parameters as recordsource for an
>>> access form.
>>> 2. How to open a stored procedure via vba to view the results
>>>
>>> For example my Prozedure is called: proc_myproc and it need two
>>> parameters like @one und @two.
>>>
>>> I would be very happy if someone could tell me how to do this.
>>>
>>> Thanks a lot.
>>>
>>> Regards
>>>
>>> Patrick
>>>
>>>
>>>

>>
>>
>>



 
Reply With Quote
 
Debra
Guest
Posts: n/a
 
      8th Feb 2010

"Patrick Pohlmann" <(E-Mail Removed)> wrote in message
news:E7A11F31-DF07-40F9-A6FA-(E-Mail Removed)...
> Hi,
>
> I am trying to work with Stored presucures insted of buliding querys
> within vba. I am working with an access .adp (Access 2007) and SQL Server
> 2005
>
> There are two quesitions I would like to know:
>
> 1. How to use a stored procedure with parameters as recordsource for an
> access form.
> 2. How to open a stored procedure via vba to view the results
>
> For example my Prozedure is called: proc_myproc and it need two parameters
> like @one und @two.
>
> I would be very happy if someone could tell me how to do this.
>
> Thanks a lot.
>
> Regards
>
> Patrick
>
>
>


 
Reply With Quote
 
Bob McClellan
Guest
Posts: n/a
 
      10th Feb 2010
Patrick
If you want to use the stored procedure as the recordsource for the form....
simply put the sp name in the recordsource property, then in the
InputParameters property put @one = 'Value 1', @two = 'Value 2'

IF this form is a subform and you want to change the data in the subform
when you click on a row in another subform....
in the on current even of form 1, put....
something like...

Forms![MyMainForm].form2.form.inputparameters = "@one = " & me.tbOne & ",
@two = " & me.tbTwo

I think you will be plesantly surprised with the speed this provides.
hth,
...bob


"Patrick Pohlmann" <(E-Mail Removed)> wrote in message
news:E7A11F31-DF07-40F9-A6FA-(E-Mail Removed)...
> Hi,
>
> I am trying to work with Stored presucures insted of buliding querys
> within vba. I am working with an access .adp (Access 2007) and SQL Server
> 2005
>
> There are two quesitions I would like to know:
>
> 1. How to use a stored procedure with parameters as recordsource for an
> access form.
> 2. How to open a stored procedure via vba to view the results
>
> For example my Prozedure is called: proc_myproc and it need two parameters
> like @one und @two.
>
> I would be very happy if someone could tell me how to do this.
>
> Thanks a lot.
>
> Regards
>
> Patrick
>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing a Stored Procedure Chad Microsoft Excel Programming 6 15th Sep 2008 02:39 PM
Accessing SQL Server Stored Procedure from VB.NET =?Utf-8?B?Y3Jpc3A5OQ==?= Microsoft Dot NET 1 28th Jan 2005 12:15 AM
Accessing SQL Server Stored Procedure from Access =?Utf-8?B?SmFjaw==?= Microsoft Access Form Coding 1 26th Aug 2004 04:46 PM
Accessing RETURN values from a Stored Procedure peteZ Microsoft ADO .NET 1 1st Sep 2003 05:42 AM
accessing multiple recordsets from a stored procedure Dr. Killer D. Goat The Man Eater Microsoft Dot NET 0 26th Aug 2003 07:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:46 PM.