Advertisement

02.25.2008 at 01:57AM PST, ID: 23189730
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Using parameters in a stored procedure from Access Project
Tags: Microsoft, Access, 2000, Acess project linked to MS SQL 2000, VBA
I have a stored procedure on my SQL 2000 box, the procedure needs two parameters.
The stored procedure is below

CREATE Procedure GetPlanID
              (            @PlanDate datetime,
            @Client varchar(10)
      )
As

Select SuppPlanID from SupportPlans where supportplans.date = @PlanDate and supportplans.ClientID = @Client
      /* set nocount on */
GO

This procedure needs to return to a record set the SuppPlanID, so that my script in VBA can utilise the ID.

My question is how can I call this stored procedure from my Access 2000 VBA code send in the parameters and ensure I have the result I need back.

Thanks
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: fellsider
Solution Provided By: kelvinsparks
Participating Experts: 2
Solution Grade: A
Views: 157
Translate:
Loading Advertisement...
02.25.2008 at 02:04AM PST, ID: 20974040

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.25.2008 at 06:50AM PST, ID: 20975773

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.25.2008 at 09:07AM PST, ID: 20977187

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.25.2008 at 12:34PM PST, ID: 20978936

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.26.2008 at 03:17AM PST, ID: 20983181

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.26.2008 at 03:30AM PST, ID: 20983259

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.26.2008 at 04:13AM PST, ID: 20983515

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.26.2008 at 04:23AM PST, ID: 20983573

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.27.2008 at 01:39PM PST, ID: 20998711

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
02.25.2008 at 02:04AM PST, ID: 20974040
I use code as listed below. Parameters can be listed (must be in the order the SP requires them

I usually am feeding field values from a form to the array e.g.Array(me.txtfield1,me.txtfield2)

Kelvin
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
    Dim cnn As ADODB.Connection
    Dim cmd As New ADODB.Command
    
   
    Set cnn = CurrentProject.Connection
    Set cmd = New ADODB.Command
    
    With cmd
        .ActiveConnection = cnn
        .CommandText = "dbo.GetPlanID"
        .CommandType = adCmdStoredProc
        .Execute Parameters:=Array(param1,param2)
    End With
    Set cmd = Nothing
    Set cnn = Nothing
Open in New Window
 
02.25.2008 at 06:50AM PST, ID: 20975773
Thanks Kelvin, your code runs without error, but how can I get hold of the result of the Select in the stored procedure?
 
02.25.2008 at 09:07AM PST, ID: 20977187

Rank: Master

The way your stored procedure is written you would need to open a recordset. See the part option 1 in te code Snippet.

If you are only returing one value you can pass it through a return parameter (see option 2 in code snippet)
For that you would have to modify the stored procedure to


CREATE Procedure GetPlanID
              (            @PlanDate datetime,
            @Client varchar(10)
      )
As

return Select SuppPlanID from SupportPlans where supportplans.date = @PlanDate and supportplans.ClientID = @Client
      /* set nocount on */
GO



1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
'***************
Option 1
'***************
Dim cnn As ADODB.Connection
    Dim cmd As New ADODB.Command
dim rst as ADODB.Recordset
    
   
    Set cnn = CurrentProject.Connection
    Set cmd = New ADODB.Command
    
    With cmd
        .ActiveConnection = cnn
        .CommandText = "dbo.GetPlanID"
        .CommandType = adCmdStoredProc
        set rst = .Execute Parameters:=Array(param1,param2)
    End With
    
    debug.print "The returned value is " & rst.Fields(0)       
 
    Set cmd = Nothing
    Set cnn = Nothing
 
'***************
Option 2
'***************
Dim cnn As ADODB.Connection
    Dim cmd As New ADODB.Command
dim rst as ADODB.Recordset
    
   
    Set cnn = CurrentProject.Connection
    Set cmd = New ADODB.Command
    
    With cmd
        .ActiveConnection = cnn
        .CommandText = "dbo.GetPlanID"
        .CommandType = adCmdStoredProc
        cmd.CommandText = "{? = call GetPlanID(?,?) }"
   cmd.Parameters.Append cmd.CreateParameter("RetVal", adInteger, adParamReturnValue)
   cmd.Parameters.Append cmd.CreateParameter("Param1", adVarChar, adParamInput, 20)
   cmd.Parameters.Append cmd.CreateParameter("Param2", adVarChar, adParamInput, 10)
  cmd.Parameters("Param1") = CStr(param1)
   cmd.Parameters("Param2") = param2
  .Execute 
  debug.print "The returned value is " & cmd.Parameters("RetVal")
    End With
    
     
    Set cmd = Nothing
    Set cnn = Nothing
Open in New Window
 
02.25.2008 at 12:34PM PST, ID: 20978936
This depends on what you want to do with the data , as my solution may not be the correct way to go. Can you advise whether you are populating a form or report for instance, or wanting to do something else with the data.

Kelvin
 
02.26.2008 at 03:17AM PST, ID: 20983181
Koutny,

Thanks for your help here.

Sadly, I can't get either of you solutions to work!

On solution 1 when I input the line
        set rst = cmd.Execute Parameters:= Array(NWPlanDate,CurrentClient)

I get a compile error: expected end of statement.  I also added in a line
        Set rst = New ADODB.Recordset
before the with cmd line but that did not help.

On solution 2 I modified the stored procedure as suggested and pasted in your code then modified the following lines.
   cmd.Parameters("Param1") = CStr(NwPlanDate)
   cmd.Parameters("Param2") = CurrentClient
when the code runs and gets to the .execute line I get the error.  'No value given for one or more required parameters'  I thought my modifications specified these values!

I guess I am incorrectly modifying your code to accept my parameters, or is there something else I am missing?
 
02.26.2008 at 03:30AM PST, ID: 20983259
Kelvin,

I will explain what my code is aiming to do - as you say my problem my lie in the way I am doing this!

The point of my code is to allow the user to create a new plan for a client, part of this is to take a copy of the detail records of the plan as a duplicate so the user can update each detail line whilst still keeping the old plan tottally intact.

IFirstly,  take a date value from an input on a form and assign this to NwPlanDate, then also assign CurrentClient with the ID of the current client that is open.

Then I run the commands below to create a new record in the SupportPlans table

'Create a new plan record for current client with the new date
sSQL = "INSERT INTO SupportPlans (Date, ClientID) VALUES ('" & NwPlanDate & "', '" & CurrentClient & "')"
DoCmd.RunSQL sSQL, True


Then I get to where I am at the moment.  I need to get hold of the PlanID of the newly created row.

Once gained I will then go to the PlanDetail table of copy each row of the current plan giving it the ID of the new plan, so the user will be presented with a full copy of the plan to update.

I hope description helps you understand where I am coming from.

Thanks again for taking you time out to help me on this.
 
02.26.2008 at 04:13AM PST, ID: 20983515

Rank: Master

Sorry, am in a rush right now so only a quick response.

I typed the code directly in post box on this website and didn't check it properly for syntax errors. Sorry about that.
The error in the first example is that there are brackets missing. The line should be
set rst = cmd.Execute (Parameters:= Array(NWPlanDate,CurrentClient))

I will need to look at what the problem is with the second option but right now the immediate thign I can spot is that you are passing the parameters in the wrong order, at least unless you changed the order in the stored procedure on the server. The first paremeter you have is a date value, and the second a string.

I need to go out now, will try to come back to you later when I am back home.
Assisted Solution
 
02.26.2008 at 04:23AM PST, ID: 20983573
Hi

Now I understand. I've struck this with an adp converted from an mdb. Easy in Access as you use a recordset to append the new record and it gives you the ID back before it saves. SQL Server needs to save the record first.  I think the SP needs altering to have an output parameter which is @@identity . This is the ID created for the INSERT statement. I'm not sure quite how to make that happen tho'. Will come back to this tomorrow - very late here.


kelvin
 
02.27.2008 at 01:39PM PST, ID: 20998711
OK, have got to the bottom of this. The VBA below will execute the stored proc and then populate the variable iRet with the ID from the table. This is my code, so you'll have to replace parameters with yours. Also I've attached the changed storedd procedure to one that returns the ID.

My stored proc is

CREATE PROCEDURE [dbo].[TestReturn]
      (
      @TD      int,
      @TR      int,
      @RID      int OUTPUT
      )
AS

INSERT INTO zTestReturn (TestDate,TestRec)
VALUES (@TD,@TR)

SET @RID =  @@IDENTITY
GO

You really only have to add the output parameter row at the top and the SET @RID line from the bottom to your existing stored proc

CBA Code in snippet
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
    Dim cnn As ADODB.Connection
    Dim cmd As New ADODB.Command
    Dim lRet As Long
    
   
    Set cnn = CurrentProject.Connection
    Set cmd = New ADODB.Command
    
    With cmd
        .ActiveConnection = cnn
        .CommandText = "dbo.TestReturn"
        .CommandType = adCmdStoredProc
        .Parameters.Append .CreateParameter("@TD", adInteger, adParamInput)
        .Parameters.Append .CreateParameter("@TR", adInteger, adParamInput)
        .Parameters.Append .CreateParameter("@RID", adInteger, adParamOutput)
        .Parameters("@TD").Value = 65
        .Parameters("@TR").Value = 72
        .Execute
        lRet = .Parameters("@RID").Value
    End With
    Set cmd = Nothing
    Set cnn = Nothing
Open in New Window
Accepted Solution
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628