473,383 Members | 1,748 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,383 software developers and data experts.

Output stored procdure in datasheet-view without using a form

Dear All,

How can I show the resultrecords of a SP.
I can be done by doubleclick the SPname?
But how to do it by code.

I want the following interface
In my form the user
1 selects a SP (combobox showing a userfrinly name)
2 adds the related parameters
3 and then click the show result-button

but the .execute command doen't show teh records.

I want the same output as you have doublclicking the SPname in the
objectwindow.

Thanks,

Filip

May 25 '06 #1
13 4826
Hi Filip,

I will assume you are using an Access ADP. In the ADP you can create a
form and base the Form's RecordSource on the SP. Just add the columns
that the sp returns to the Form from the field list in the Form
designer. Place the form in datasheet view. You can make it a subform
and show it from a mainform.

If you are not using an ADP but an mdb, then you use ADO to generate a
recordset. Write that recordset to a table and base a form on that
table.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
May 25 '06 #2
DoCmd.OpenStoredProcedure "SpGetFFDBAAccounts"

There are two optional parameters:

AcView -> acViewNormal || acViewPivotChart || acViewPivotTable ||
acViewPreview
and
DataMode -> acEdit || acAdd || AcReadOnly.

I have not used these. Datamode may be useful.

May 25 '06 #3
DoCmd.OpenStoredProcedure "Spxxxxx" asks the parameters again.
I would like to open the SP without asking the parametervalues again, just
pick them from the formcontrols.
In a table I store the parameters related to each SP with a usersfrindly
question.
I was hoping to be able to add new SPs without changing the interface,
without adding a form for each new SP

"Lyle Fairfield" <ly***********@aim.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
DoCmd.OpenStoredProcedure "SpGetFFDBAAccounts"

There are two optional parameters:

AcView -> acViewNormal || acViewPivotChart || acViewPivotTable ||
acViewPreview
and
DataMode -> acEdit || acAdd || AcReadOnly.

I have not used these. Datamode may be useful.

May 26 '06 #4
I was hoping to be able to add new SPs without changing the interface,
without adding a form for each new SP and still provide the parametervaleus
in the forms controls.

"Rich P" <rp*****@aol.com> wrote in message
news:5z***************@news.uswest.net...
Hi Filip,

I will assume you are using an Access ADP. In the ADP you can create a
form and base the Form's RecordSource on the SP. Just add the columns
that the sp returns to the Form from the field list in the Form
designer. Place the form in datasheet view. You can make it a subform
and show it from a mainform.

If you are not using an ADP but an mdb, then you use ADO to generate a
recordset. Write that recordset to a table and base a form on that
table.

Rich

*** Sent via Developersdex http://www.developersdex.com ***

May 26 '06 #5
Filips Benoit wrote:
DoCmd.OpenStoredProcedure "Spxxxxx" asks the parameters again.


Sub OpenStoredProcedure(ProcedureName, [View As AcView = acViewNormal],
[DataMode As AcOpenDataMode = acEdit])
Member of Access.DoCmd

View and DataMode are optional parameters. A Call to the Sub should not
ask for these parameters, and will not in Access 2003. Look at the
Intellisense; if the parameters are in [square brackets] they are
optional and not required.

Regardless, you should be able to use

DoCmd.OpenStoredProcedure "Spxxxxx", acViewNormal, acEdit, or whataver
parameters you want.

If you are still having problems tell us the version of Access. I've
assumed you are using an ADP.

May 26 '06 #6
Its about the SP-parameters not the parameters of the Sub
(DoCmd.OpenStoredProcedure).
I want to input the SP-parameters in my form and check the datatype befor
opening the SP.
BUT with DoCmd.OpenStoredProcedure "Spxxxxx" I can't provide the
SP-parameters to the SP and it ask them again !

I want the following interface
A form where the user
1 selects a SP (combobox showing a userfrinly SP-names stored in a table
CUSTOM_QUERY)
2 adds the related parameters ( stored in another
tableCUSTOM_QUERY_PARAMETERS)
3 Checking the parametervalues befor opening the SP
4 Opening the SP as table and providing the SP-parameters by code.

1,2 and 3 is no problem but I want to do 4 only with code without creating a
new form for each SP so the access-inteface should not be edited for each
new SP !!!

Thanks,

Filip
"Lyle Fairfield" <ly***********@aim.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
Filips Benoit wrote:
DoCmd.OpenStoredProcedure "Spxxxxx" asks the parameters again.


Sub OpenStoredProcedure(ProcedureName, [View As AcView = acViewNormal],
[DataMode As AcOpenDataMode = acEdit])
Member of Access.DoCmd

View and DataMode are optional parameters. A Call to the Sub should not
ask for these parameters, and will not in Access 2003. Look at the
Intellisense; if the parameters are in [square brackets] they are
optional and not required.

Regardless, you should be able to use

DoCmd.OpenStoredProcedure "Spxxxxx", acViewNormal, acEdit, or whataver
parameters you want.

If you are still having problems tell us the version of Access. I've
assumed you are using an ADP.

May 26 '06 #7
I think I understand ... Spxxxx requires input parameters? right? I'll
think on that ...

May 26 '06 #8
right
Thanks for following me !

Filip

"Lyle Fairfield" <ly***********@aim.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
I think I understand ... Spxxxx requires input parameters? right? I'll
think on that ...

May 26 '06 #9
This works here but it is TRÈS ugly! I do not offer it as anything
exemplary.

SpGetLoanInterest has one input parameter; @AnnualInterest defaulting
to 1.08 and this is changed to 1.125 for the "running". It does not
matter if the Paramaters have default values. The entire script of the
Procedure is appended in hopes that it may help you or anyone
understand.

**** begin code ****
Option Compare Database
Option Explicit

Sub temp()
Dim TSQL As String
On Error Resume Next
CurrentProject.Connection.Execute "DROP Procedure TempProcedure"
On Error GoTo 0
TSQL = GetSQLStringFromSP("SpGetLoanInterest")
TSQL = Replace(TSQL, "@AnnualRate", "1.125")
CurrentProject.Connection.Execute "CREATE PROCEDURE TempProcedure
AS " & TSQL
DoCmd.RunCommand acCmdViewStoredProcedures
Application.RefreshDatabaseWindow
DoCmd.OpenStoredProcedure "TempProcedure"
CurrentProject.Connection.Execute "DROP Procedure TempProcedure"
End Sub

Public Function GetSpTSQL(ByVal SpName As String) As String
Dim TSQL As String
TSQL = "SELECT text from SysComments c JOIN SysObjects o ON c.ID =
o.ID WHERE o.Name = '" & SpName & "'"
GetSpTSQL =
Trim(CurrentProject.Connection.Execute(TSQL).Colle ct(0))
End Function

Public Function GetSQLStringFromSP(ByVal SpName As String) As String
Dim spTSQL As String
Dim Position As String
spTSQL = GetSpTSQL(SpName)
Position = InStr(spTSQL, "AS") + 2
GetSQLStringFromSP = Mid$(spTSQL, Position)
GetSQLStringFromSP = Replace(GetSQLStringFromSP, "RETURN", "")
GetSQLStringFromSP = Trim(GetSQLStringFromSP)
End Function
**** end code ****

**** T-SQL in spGetLoanInterest ****
ALTER PROCEDURE spGetLoanInterest
@AnnualRate float=1.08
AS

DECLARE @Balance smallmoney
DECLARE @DailyRate float
DECLARE @Date smalldatetime
DECLARE @Days int
DECLARE @DaysInYear float
DECLARE @DaysInYearReciprocal float
DECLARE @Interest smallmoney
DECLARE @Period float
DECLARE @PreviousDate smalldatetime

EXECUTE spLoanInterest

SET @DaysInYear = 365
SET @Period = 1
SET @DaysinYearReciprocal=(@Period/@DaysInYear)
SET @DailyRate = POWER(@AnnualRate,@DaysInYearReciprocal)
SELECT @Date = Max([Date]) FROM Loan
SET @Days = DATEDIFF(dayofyear, @Date, GETDATE())
SELECT Top 1 @Balance = Balance FROM Loan Order By [Date] desc, ID
desc
SET @Interest = POWER(@DailyRate, @Days) * @Balance - @Balance
SET @Balance = @Balance + @Interest

SELECT [Date], [Amount], [Note], [Interest], [Balance] FROM [Loan]

UNION

SELECT
GETDATE() as DATE ,
0 AS Amount,
'Current Balance' AS Note,
@Interest AS Interest,
@Balance AS Balance

ORDER BY Date

RETURN
**** end T-SQL ****

I can't remember what this Sproc actually does; I just chose it as
something to work on.

May 26 '06 #10
Codeline
DoCmd.RunCommand acCmdViewStoredProcedures
trigger error Runtime error 2046 = "The command or action
ViewStoredProcedures is not available now!"

"Lyle Fairfield" <ly***********@aim.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
This works here but it is TRÈS ugly! I do not offer it as anything
exemplary.

SpGetLoanInterest has one input parameter; @AnnualInterest defaulting
to 1.08 and this is changed to 1.125 for the "running". It does not
matter if the Paramaters have default values. The entire script of the
Procedure is appended in hopes that it may help you or anyone
understand.

**** begin code ****
Option Compare Database
Option Explicit

Sub temp()
Dim TSQL As String
On Error Resume Next
CurrentProject.Connection.Execute "DROP Procedure TempProcedure"
On Error GoTo 0
TSQL = GetSQLStringFromSP("SpGetLoanInterest")
TSQL = Replace(TSQL, "@AnnualRate", "1.125")
CurrentProject.Connection.Execute "CREATE PROCEDURE TempProcedure
AS " & TSQL
DoCmd.RunCommand acCmdViewStoredProcedures
Application.RefreshDatabaseWindow
DoCmd.OpenStoredProcedure "TempProcedure"
CurrentProject.Connection.Execute "DROP Procedure TempProcedure"
End Sub

Public Function GetSpTSQL(ByVal SpName As String) As String
Dim TSQL As String
TSQL = "SELECT text from SysComments c JOIN SysObjects o ON c.ID =
o.ID WHERE o.Name = '" & SpName & "'"
GetSpTSQL =
Trim(CurrentProject.Connection.Execute(TSQL).Colle ct(0))
End Function

Public Function GetSQLStringFromSP(ByVal SpName As String) As String
Dim spTSQL As String
Dim Position As String
spTSQL = GetSpTSQL(SpName)
Position = InStr(spTSQL, "AS") + 2
GetSQLStringFromSP = Mid$(spTSQL, Position)
GetSQLStringFromSP = Replace(GetSQLStringFromSP, "RETURN", "")
GetSQLStringFromSP = Trim(GetSQLStringFromSP)
End Function
**** end code ****

**** T-SQL in spGetLoanInterest ****
ALTER PROCEDURE spGetLoanInterest
@AnnualRate float=1.08
AS

DECLARE @Balance smallmoney
DECLARE @DailyRate float
DECLARE @Date smalldatetime
DECLARE @Days int
DECLARE @DaysInYear float
DECLARE @DaysInYearReciprocal float
DECLARE @Interest smallmoney
DECLARE @Period float
DECLARE @PreviousDate smalldatetime

EXECUTE spLoanInterest

SET @DaysInYear = 365
SET @Period = 1
SET @DaysinYearReciprocal=(@Period/@DaysInYear)
SET @DailyRate = POWER(@AnnualRate,@DaysInYearReciprocal)
SELECT @Date = Max([Date]) FROM Loan
SET @Days = DATEDIFF(dayofyear, @Date, GETDATE())
SELECT Top 1 @Balance = Balance FROM Loan Order By [Date] desc, ID
desc
SET @Interest = POWER(@DailyRate, @Days) * @Balance - @Balance
SET @Balance = @Balance + @Interest

SELECT [Date], [Amount], [Note], [Interest], [Balance] FROM [Loan]

UNION

SELECT
GETDATE() as DATE ,
0 AS Amount,
'Current Balance' AS Note,
@Interest AS Interest,
@Balance AS Balance

ORDER BY Date

RETURN
**** end T-SQL ****

I can't remember what this Sproc actually does; I just chose it as
something to work on.
May 26 '06 #11
Well Filips all this is doing is being extra careful to make sure the
list of SPROCs in the Database Window is refreshed. (Access looks in
the Database Window to find the names of Objects, even when it's
hidden; actually it's never hidden but just deactivated and all its
components made the same color as the background.)

Regardless

Try removing that line:

DoCmd.RunCommand acCmdViewStoredProcedures

entirely; it's probably redundant.

May 26 '06 #12
It didn't work but I found another solution thanks to your code.
The SP has no parameters but a tempstring as placeholder: param1, param2,
param3 etc.
I ALTER the SP 2 times: 1 to set the users parametervalues and after showing
the results I Alter the SP back to its original SP-TSQL with the tempstring
as placeholders.

? Is this a good solution ?

Thanks³,

Filip

'Alter SP-TSQL by replacing Param1 > parametervalue1 etc. (Related
parameters are set visible while selecting a SP)
TSQL = GetSQLStringFromSP(Me.CmbQuery.Column(2))
For iLoop = 1 To 9
If Me("TxtParValue" & CStr(iLoop)).Visible Then
TSQL = Replace(TSQL, "Param" & CStr(iLoop), Me("TxtParValue" &
CStr(iLoop)).value)
End If
Next iLoop
CurrentProject.Connection.Execute "ALTER PROCEDURE " &
Me.CmbQuery.Column(2) & " AS " & TSQL

'Show results
DoCmd.OpenStoredProcedure Me.CmbQuery.Column(2)

'Restore SP-TSQL = Alter to original SP-TSQL
For iLoop = 1 To 9
If Me("TxtParValue" & CStr(iLoop)).Visible Then
TSQL = Replace(TSQL, Me("TxtParValue" & CStr(iLoop)).value,
"Param" & CStr(iLoop))
End If
Next iLoop
CurrentProject.Connection.Execute "ALTER PROCEDURE " &
Me.CmbQuery.Column(2) & " AS " & TSQL


"Lyle Fairfield" <ly***********@aim.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Well Filips all this is doing is being extra careful to make sure the
list of SPROCs in the Database Window is refreshed. (Access looks in
the Database Window to find the names of Objects, even when it's
hidden; actually it's never hidden but just deactivated and all its
components made the same color as the background.)

Regardless

Try removing that line:

DoCmd.RunCommand acCmdViewStoredProcedures

entirely; it's probably redundant.

May 26 '06 #13
Only you can know if it's a good solution.
Does it do what you want?
Is it fast enough?
Does it cause a mess?
If it's yes, yes, no then it's probably an OK solution.

May 26 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steve Holden | last post by:
Has anyone, with any driver whatsoever, managed to retrieve output parameters from a SQL Server stored procedure? I've just been rather embarrassed to find out it's not as easy as it might seem,...
2
by: Begoña | last post by:
in my java application I've made a call to this stored procedure CREATE procedure pruebaICM @pANI varchar(20), @pTABLA varchar(20), @pInsert varchar(500), @pUpdate varchar(1000), @pFLAG...
5
by: Jay Chan | last post by:
I am trying to use a command line program to run a stored procedure that generates output in a comma-delimitted format. Somehow, ISQL or OSQL always wrap the lines at 256 characters. I believe this...
3
by: Bruce | last post by:
Since DBlib is no longer the suggested method for connecting back to sql server from an Extended Stored Procedure, has anyone built any extended stored procedures that use other connection methods...
4
by: Steven | last post by:
I'm calling a stored procedure which has an output parameter of type int. Once the stored procedure is executed, I want to check the value of the parameter in case it is null. However, when the a...
8
by: Yusuf INCEKARA | last post by:
I have a stored procedure : CREATE PROCEDURE STP_GETSTORELIST @RETCUR CURSOR VARYING OUTPUT AS set @RETCUR = CURSOR FORWARD_ONLY STATIC FOR SELECT ID,STORE_NAME FROM T_INF_STORE ORDER BY...
8
by: Christopher Weaver | last post by:
I'm having trouble accessing the value of an output parameter of a stored procedure. The SP looks like this: SET TERM ^ ; CREATE PROCEDURE SP_NEW_TASK RETURNS ( "uidTask" INTEGER) AS begin
4
by: Sara | last post by:
How to call a .net dll method from sql server 2000 stored procdure
2
by: satish | last post by:
hi, i am a learner of ms -sql server 2000, i had a doubt in stored procedures suppose i have a data base having 20 tables, all the tables have a column named--DATE can we write a store...
8
by: Milkstr | last post by:
Can anyone help, i'm just starting out with MS SQL on a new web page and i'm having problems writing a stored procdure, its for a simple forum on a web page. I have a table with the main forum...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.