Home > Visual Basic Programming > Calling parametrized stored procedure from MS Access

Calling parametrized stored procedure from MS Access



Hi

I am trying to pass date parameters from MS Access form to stored procedure on SQL server . When I execute the code I am getting an error on "qd.execute " The error message is



Number: 3065

Source : DAO.QueryDef

Text: Can not execute selected Query.





I am pasting the code here so If someone have any idea what would be the problem



Dim db As Database

Dim qd As QueryDef

Dim rs As Recordset

Dim fld As Field

Dim datStartDate, datEndDate As Date



'Getting the user inputs from Ms Access form

datStartDate = [Form_Archive Information].StartDate

datEndDate = [Form_Archive Information].EndDate

Set db = CurrentDb ' Setting the database as current Database

On Error Resume Next

db.QueryDefs.Delete ("GCS_PQ_ARCHIVED_RECORDS") 'deleting the old defination of pass-through query

On Error GoTo ErrorHandler

Set qd = db.CreateQueryDef("GCS_PQ_ARCHIVED_RECORDS") 'define new query defination

qd.ReturnsRecords = False ' Query do not retrieve records

'Connection string

'user id and password is deliberately hide before posting the code

qd.Connect = "ODBC;DSN=DSN_RACK_BARREL; UID=kabxxxx, PWD=xxxxx;DATABASE=RACKBARREL"

qd.SQL = "Exec GCS_SP_Archived_Records " & "'" & datStartDate & "'" & ", " & "'" & datEndDate & "'"

qd.Execute

qd.Close



ErrorHandler:

DisplayDAOError





Note: I Already add teh The reference libraries Microsoft ADO 3.6 reference library

I have permission on databse and all the related tables .

if I run the above pass-through query in development mode it works.

stored procedure was tested .



The problem is on db.execute line. It fails whenever I run the code

I also check the permissions on related tables for the user used in connection string. I don't know where the problem is.



Please help !!!!

    
Guest


You should use an Access Project instead of DAO, what version of Access are you using?

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved