Solved

Passing parameters from Access to an sp

Posted on 2002-03-12
2
156 Views
Last Modified: 2008-03-06
I have the following stored procedure in a SQLServer db. The sp takes 3 parameters, one text and two dates.


CREATE PROCEDURE sp_DonationType_TotalAmount

@myDonationType varchar, @myBeginDate datetime, @myEndDate datetime
AS

select Sum(a.Amount) as SumAmount
from tblDonationAllocations a inner join tblDonations d on a.DonationID = d.DonationID
where (a.DonationType = @myDonationType) and (d.DonationDate between @myBeginDate and @myEndDate)
GO


I have an Access Project (.adp) front-end to the db and use VBA code to run the sp and create a recordset. The code that passes the parameters using a command object is:


Dim myBeginDate, myEndDate as Date
Dim myDonationType as String
Dim mySumAmount as Currency
...

myCmd.Parameters("@myBeginDate") = myBeginDate
myCmd.Parameters("@myEndDate") = myEndDate
myCmd.Parameters("@myDonationType") = myDonationType
   
Set myRs = myCmd.Execute
With myRs
   mySumAmount = !SumAmount
   .Close
End With
...


The value passed as myDonationType is a string, eg "ADMIN" and the dates passed are entered via a Form like this: 3/12/02 (for December 3, 2002). This is UK format.

Can you please tell me what I have done wrong as I always get a data type error for the string parameter. Also the dates don't seem to work correctly; how do I fix that?

Thanks.
0
Comment
Question by:naqayya
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
Comment Utility
Change the procedure header to this:

CREATE PROCEDURE sp_DonationType_TotalAmount

@myDonationType varchar(100), @myBeginDate datetime, @myEndDate datetime
AS
...

The problem is that if you don't give a size for the varchar, it will be 1 by default... and thus any value you pass that is larger than 1 will raise that error...

For the dates values, you should declare your variable like this:
Dim myBeginDate as Date
dim myEndDate as Date
Your way the Begindate was declared as variant!

For the rest it should work, otherwise you can try to supply the date format like this yyyy/mm/dd ...


CHeers
0
 

Author Comment

by:naqayya
Comment Utility
Thanks a million angelIII! Full marks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now