Re: Calling SQL Stored Proc from Access (with Parameters)

From: Duane Hookom (duanehookom_at_NoSpamHotmail.com)
Date: 02/17/05


Date: Thu, 17 Feb 2005 11:21:53 -0600

You can put the code in the after update of your "form field". After the
text box (or combo box) is updated by the user, have the code change the SQL
property of the pass-through query. Assuming your pass-through is named
"qsptMyPT" and the text box/control is named "StatementNumber" then the code
in the after update event of the control "StatementNumber" would be:

Dim strSQL as String
strSQL = "exec spr_myReport " & Me.StatementNumber
CurrentDb.QueryDefs("qsptMyPT").SQL = strSQL

This would be in the form's code window.

-- 
Duane Hookom
MS Access MVP
--
"Jessard" <Jessard@discussions.microsoft.com> wrote in message 
news:AA9E5362-C47C-4396-BCCD-69E7A2382F04@microsoft.com...
> Thanks again for your responses but i'm not quite there yet.
>
> This is the background.  I have an access database and a SQL database. 
> The
> access database has a heap of linked SQL tables through 'Linked Table
> Manager' to the SQL database.  I have now created a Pass-Through query in
> access which, as far as I understand, can run a piece of SQL directly on 
> the
> SQL database it links to.  This works fine but I need to be able to change
> the parameter that is in the Pass-Through query dynamically, ie. based on 
> the
> value of a form field that is open.
>
> I have had good responses that sound like they will do what I want but I
> need to know where to type the code that is given - considering I am using 
> an
> access database.  I have tried Duane's code in the query but that is
> obviously not the right spot for it.  It looks like VB code, I don't know
> where to put it though
>
> Jesse
>
>
> "Barry Jon" wrote:
>
>> Jesse,
>>
>> not sure what your connection method is.  I believe, using ADO, that you
>> could do something like this;
>>
>>     Dim cmd As ADODB.Command
>>
>>     Set cmd = New ADODB.Command
>>     cmd.ActiveConnection = [relevant connection]
>>     cmd.CommandType = adCmdStoredProc
>>     cmd.CommandText = "spr_my_report"
>>
>>     cmd.Execute , Array([Parameter Value1], [Parameter Value2]...)
>>
>> Let me know if I am missing the mark or if this works for you :-)
>>
>> Regards
>>
>> Barry-Jon
>>
>> "Jessard" <Jessard@discussions.microsoft.com> wrote in message
>> news:E10C43B1-8356-4A8A-99EA-51F5624BF3B5@microsoft.com...
>> > Hi
>> >
>> > I am aware that one can run an SQL Server stored proc from Access and
>> > return
>> > records and even pass in parameters to the stored proc to get the 
>> > desired
>> > result.  At the moment I am doing this with a "Pass-through" query with
>> > Hard-Coded parameters.
>> >
>> > What I want to do however is have the parameter that is passed in to 
>> > the
>> > stored proc from access created dynamically from a form in Access.
>> >
>> > eg.
>> >
>> > exec spr_my_report [forms]![frmeomreports]![statementnumber]
>> >
>> > instead of
>> >
>> > exec spr_my_report 55
>> >
>> >
>> > Or equivalent, any ideas?
>> >
>> > Thanks,
>> > Jesse
>>
>>
>> 


Relevant Pages

  • Re: ODBC Error
    ... You're loading the Jet engine and using it for SQL ... Create a stored procedure instead of a buinch of views. ... > pass-through query into the local table. ... >>CREATE VIEW vBackOrder AS ...
    (microsoft.public.sqlserver.odbc)
  • Re: VB or?
    ... I know you can use an Access database with it, but it's not the standard, instead using compact SQL for the desktop, or the free version of SQL would be the more "in the box" approaches. ... If you haven't been programming for 12 years, then I'd suggest try the .NET version and see how you go. ... You can buy a .NET standard version and downgrade I believe, but not sure on that status now as officially VB6 is no longer a supported product. ...
    (microsoft.public.vb.general.discussion)
  • Re: Anyone tell me whats wrong with this SQL statement?
    ... That sounds like an SQL error telling you that you are not accounting ... am also working on a Photo Album which uses an Access ... > PS - just to cover every area, the data types in Access database are as ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: VB or?
    ... I know you can use an Access database with it, but it's not the standard, instead using compact SQL for the desktop, or the free version of SQL would be the more "in the box" approaches. ... If you haven't been programming for 12 years, then I'd suggest try the .NET version and see how you go. ... You can buy a .NET standard version and downgrade I believe, but not sure on that status now as officially VB6 is no longer a supported product. ...
    (microsoft.public.vb.general.discussion)
  • Re: VB or?
    ... using compact SQL for the desktop, or the free version of SQL (SQL ... as officially VB6 is no longer a supported product. ... I did some VB programming about 12 years ago, got as far as VB 4.0. ... again with VB and having problems opening an Access database. ...
    (microsoft.public.vb.general.discussion)

Loading