473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Avoiding Parameter Prompts for Stored Procs

Hi,

I have an ADP App connecting to a SQL 2005 database. I have a continous form which I want to fill myself based on a stored procedure call I do in VBA. I've tried using Me.Recordset and Me.RecordSource. In both cases, if my procedure has more than one parameter, it prompts me for the 2nd parameter every time - even if I've supplied it in my stored procedure call.

Does anyone have any tips on how to avoid this prompt? It's driving me crazy!

Thanks!
Sep 28 '07 #1
5 2609
Jim Doherty
897 Expert 512MB
Hi,

I have an ADP App connecting to a SQL 2005 database. I have a continous form which I want to fill myself based on a stored procedure call I do in VBA. I've tried using Me.Recordset and Me.RecordSource. In both cases, if my procedure has more than one parameter, it prompts me for the 2nd parameter every time - even if I've supplied it in my stored procedure call.

Does anyone have any tips on how to avoid this prompt? It's driving me crazy!

Thanks!
If you are not using the imputparameters property of the form and basically calling a sproc from code I cannot see where you are being prompted for a parameter at all (that is if you are providing them correctly). It could quite be a simple case of you simply not appending to the collection? but without seeing any code from you its difficult to advise

Regards

Jim
Sep 28 '07 #2
If you are not using the imputparameters property of the form and basically calling a sproc from code I cannot see where you are being prompted for a parameter at all (that is if you are providing them correctly). It could quite be a simple case of you simply not appending to the collection? but without seeing any code from you its difficult to advise

Regards

Jim
Thanks Jim. I'm curious what you mean by "not appending to the collection". Here's some more information. My code looks something like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.         strSql = "EXEC dbo.GPIA_GetPartnerTransactions @show_whole_year=" & show_whole_year & ", @as_of_date = '" & as_of_date & "'"
  3.         'Me.RecordSource = strSql
  4.         Set Me.Recordset = ExecSQLRS(strSql, strErrorDesc, intError)
  5. End Sub
The function ExecSQLRS is one that I made which returns a recordset using ADO. I tried using both that and the Me.RecordSource above. I've tried all combinations of supplying inputparamters, not supplying them, etc. Another interesting twist: it only prompts me when my procedure has more than one parameter.

When I do the exact same thing but with only one parameter it works fine. When I add a second parameter, it seems Access keeps automatically adding the following to the InputParameters and prompting me:

InputParameters: ? [AllowDefault] = as_of_date

When I step through in debug mode it's odd - the parameter prompt comes after my recordset or recordsource assignment. It seems like Access is trying to do something on its own even after I assign my own recordset.

Thanks again,
H
Sep 28 '07 #3
Jim Doherty
897 Expert 512MB
Thanks Jim. I'm curious what you mean by "not appending to the collection". Here's some more information. My code looks something like this:

Private Sub Form_Load()
strSql = "EXEC dbo.GPIA_GetPartnerTransactions @show_whole_year=" & show_whole_year & ", @as_of_date = '" & as_of_date & "'"
'Me.RecordSource = strSql
Set Me.Recordset = ExecSQLRS(strSql, strErrorDesc, intError)
End Sub

The function ExecSQLRS is one that I made which returns a recordset using ADO. I tried using both that and the Me.RecordSource above. I've tried all combinations of supplying inputparamters, not supplying them, etc. Another interesting twist: it only prompts me when my procedure has more than one parameter.

When I do the exact same thing but with only one parameter it works fine. When I add a second parameter, it seems Access keeps automatically adding the following to the InputParameters and prompting me:

InputParameters: ? [AllowDefault] = as_of_date

When I step through in debug mode it's odd - the parameter prompt comes after my recordset or recordsource assignment. It seems like Access is trying to do something on its own even after I assign my own recordset.

Thanks again,
H

Ok well again not all the code is there to look at but you are basically asking to return a recordset to the form and there are various ways to do that. The simplest way is to (early bind) set the recordsource of the subform to the name of the store procedure itself with the owner predicate which in your case would simply be

dbo.GPIA_GetPartnerTransactions

In this case the inputparameters property of the form would be the provider of the parameters for the procedure to which the form is BOUND. You would place these parameters into that property.FORM......DESIGN....View....Properties... InputParameters

I do not know what the datatypes of your parameter values are.... for me sat here they could be numeric or varchar or indeed anything else but I am assuming show_whole_year might be a varchar(3) a YES value or something like that. I will also assume that the as_of_date parameter might be an actual date value you are wanting to pass in.

The InputParameters of the form could then be set by you in the ON_LOAD event if you so wished so that the stored procedure has something to work with when it kicks in when the form actually opens

Without knowing the datatypes and your system its difficult therefore I am going to give you an example of something related to one of MY forms which is bound to a stored procedure and which also requires parameters and where I SET those parameters at runtime (the values of which are being passed from another form which is currently open in memory

My form has its recordsource set simply to

dbo.usp_qryFetchList

My form to open relies on a date and the value of a particular caption from one of 26 toggle buttons in an option group located on the other 'open' form (a bit like a telephone directory if you get me where I use classic alpha filter buttons. you can see the example of this in Northwind)

The on load event of my form has this code

Expand|Select|Wrap|Line Numbers
  1.  
  2. myparams = "@datefrom='" & Format(Forms!frmMainMenu!DateFromCrit, "mm/dd/yyyy") & "'"
  3.     myparams = myparams & ",@dateto='" & Format(Forms!frmMainMenu!DateToCrit, "mm/dd/yyyy") & "'"
  4.     myparams = myparams & ",@grpazfilter='" & Forms!frmTelephoneList("Btn" + Format$(grpazfilter)).Caption & "'"
  5. Me.InputParameters = myparams
  6.  

Now this is all well and good because the form is an early bind and I want the functionality of continuous form. If YOUR form is something you want to remain as UNBOUND where you populate the controls using some recordset method as I am assuming might be the case given you have some kind of function there (ExecSQLRS(strSql, strErrorDesc, intError)) then the approach would be different and you would want to return an ADO recordset based on parameters passed in code then you are going to need to look at CREATEPARAMETER method

Below is the area that you need to be looking look at to return the ADO recordset if that is indeed what you are doing by your function? It is THIS area that I was talkiing about when I referred to APPENDING to the collection (its easy to create a parameter and forget to append then wonder why nothing works if you get me)

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private CN As ADODB.Connection
  3. Private CMD As ADODB.Command
  4. Private PRM As ADODB.Parameter
  5. Private RS As ADODB.Recordset
  6. Set PRM = New ADODB.Parameter
  7.     Set PRM = CMD.CreateParameter("TheNameOfYourFirstParam", adInteger, adParamInput, , TheFirstVariableToPassIn)
  8.         CMD.Parameters.Append PRM
  9.     Set PRM = CMD.CreateParameter("TheNameOfYourSecondParam", adVarChar, adParamInput, 11, TheSecondVariableToPassIn)
  10.         CMD.Parameters.Append PRM
  11.     Set RS = New ADODB.Recordset
  12.     Set RS.Source = CMD
  13.         RS.CursorType = adOpenStatic
  14.         RS.LockType = adLockOptimistic
  15.         RS.Open
  16.  
The above is only an 'example' of where you need to go obviously the values contained in it are representative like the 11 in the second value is datasize and whether you need a client side or server side cursor for whatever reason you may or may not have I havent a clue

Hope this helps you but without viewing everything you have there I have to guess this end

Most of the time I stay away from too much convaluted coding in favour of binding because its simple to do, works (never failed me) and unless specifically needed why complicate matters SQL Server is way fast as it is when properly indexed and optimised

Regards

Jim
Sep 28 '07 #4
Jim - thanks for the detailed explanation. I had actually come back here to post that I had come up with a solution - and its the same as what you suggested as your first option. It works properly when I just change the inputParameters as necessary and then do a ReQuery. For me now this is great - but I have a feeling that if I wanted to change the actualy stored procedure being executed (RecordSource) I would be back to my old problem.

I'm curious to know if your second method would've solved my problem too. I'm too busy to try it right now unfortunately. My ExecRS function I made was sucesfully retrieving the recordset though. The prompt always came up once I tried to assign the recordset to the form. That's why I'm not sure if using the parameter property of ADO would've made a difference. For some reason whenever changing the recordsource or recordset property of the form on the fly, Access was trying to assign its own InputParameters - which was causing the prompting. For example, here:

Expand|Select|Wrap|Line Numbers
  1. Set RS = ExecSQLRS(strSql, strErrorDesc, intError)
  2. Set Me.Recordset = RS
  3.  
when debugging, the prompt happens on line 2, not line 1. As part of line 2, Access is apparently trying to set its own InputParameters for some reason.

Anyway, I'm just happy it's working now. Thanks again.

H
Sep 28 '07 #5
ADezii
8,834 Expert 8TB
Thanks Jim. I'm curious what you mean by "not appending to the collection". Here's some more information. My code looks something like this:

Private Sub Form_Load()
strSql = "EXEC dbo.GPIA_GetPartnerTransactions @show_whole_year=" & show_whole_year & ", @as_of_date = '" & as_of_date & "'"
'Me.RecordSource = strSql
Set Me.Recordset = ExecSQLRS(strSql, strErrorDesc, intError)
End Sub

The function ExecSQLRS is one that I made which returns a recordset using ADO. I tried using both that and the Me.RecordSource above. I've tried all combinations of supplying inputparamters, not supplying them, etc. Another interesting twist: it only prompts me when my procedure has more than one parameter.

When I do the exact same thing but with only one parameter it works fine. When I add a second parameter, it seems Access keeps automatically adding the following to the InputParameters and prompting me:

InputParameters: ? [AllowDefault] = as_of_date

When I step through in debug mode it's odd - the parameter prompt comes after my recordset or recordsource assignment. It seems like Access is trying to do something on its own even after I assign my own recordset.

Thanks again,
H
  1. Could you post the InputParameters Property String that you were using?
  2. Are the Parameters in the String separated by a comma?
  3. Can you post the Stored Procedure?
Sep 29 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Danny | last post by:
Using small stored procs or sp_executesql dramatically reduces the number of recompiles and increases the reuse of execution plans. This is evident from both the usecount in syscacheobjects,...
1
by: LineVoltageHalogen | last post by:
Greetings All, currentley there is a heated discussion in my place of work over which method is better/more efficient for simple selects. Background: 1.) Simple Application that uses sql server...
6
by: Dave | last post by:
1) I know that we can define an external proc to be Fenced or NotFenced on "CREATE PROCEDURE" command. I don't see the FENCED / NOT FENCED option on "Create Procedure" for SQL stored procs. Is...
7
by: trint | last post by:
My boss wants me to use stored procedures, but I thought somehow that using c# that ADO.Net was better. Any help is appreciated. Thanks, Trint
45
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
3
by: Jim Andersen | last post by:
Just to let you know, and to help any future sorry sods who gets trapped in the same black hole...... You can't just copy/move a working sql-statement into a stored procedure. Working with a...
1
by: kentk | last post by:
Is there a difference in how SQL Server 7 and SQL 2000 processes SQL passed from a program by an ADO command object. Reason I ask is I rewrote a couple applications a couple years ago were the SQL...
15
by: Burt | last post by:
I'm a stored proc guy, but a lot of people at my company use inline sql in their apps, sometimes putting the sql in a text file, sometimes hardcoding it. They don't see much benefit from procs, and...
8
by: Frank Calahan | last post by:
I've been looking at LINQ and it seems very nice to be able to make queries in code, but I use stored procs for efficiency. If LINQ to SQL only works with SQL Server and stored procs are more...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.