Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Passing parameters from Access to an sp

Posted on 2002-03-12
2
Medium Priority
?
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 400 total points
ID: 6856119
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
ID: 6856156
Thanks a million angelIII! Full marks!
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

722 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