Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Query Designer to make Pass Through query

Status
Not open for further replies.

pokeymonsc

Technical User
Jul 27, 2004
29
0
0
US
I've created a pass-through query to a stored procedure on SQL-Server using Query Designer in access. I've done this with another SP and the method works fine. The code for this SP is:
EXECUTE spDeleteChildRecords [base_data.mmes_number]

What I'm unsure about this time if this is the correct code to pass a parameter (mmes_number) to the SP. I have a button on my Base form:
Dim stDocName As String
stDocName = "DeleteChildRecords"
DoCmd.OpenQuery stDocName, acNormal, acEdit

and this will run the SP but I want to make absolutely sure that the 'mmes_number' that's in the current record of the 'base' form is passed to the SP, otherwise I'm worried that ALL the records in the database will be deleted not just those with this mmes_number.

Some of the code in the SP are as follows:

CREATE PROCEDURE dbo.spDeleteChildRecords (@id1 varchar(10))
AS
BEGIN
IF @id1 IS NOT NULL
DELETE FROM BASE_DATA WHERE MMES_NUMBER = @id1
(Repeated with 21 other tables)
END
GO

There are a lot of tips in the forum on how to use VBA code to access the server directly and run the SP, but nothing on using the query designer to set up the pass-through and how to send a parameter to the query.
 
Well, what about creating a copy of the database for testing, and you could see if any problems arise while still maintaining the integrity of the original? Or, for simplification of code - do the testing on the original, then when complete, delete the original (if problems), and change the name and/or path of the copy to that of the original?

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
I appreciate the answer, but I think I emphasized the wrong point. My SP code protected the database (if @id1 is not null). I tested the procedure and found this out. If my code in the pass through query is:
EXECUTE spDeleteChildRecords 'zwert1' the SP will delete those records from the database. But is the code is:
EXECUTE spDeleteChildRecords 'me.mmis_number' and on the form in the mmis_number textbox is zwert1 the # is not passed to the query and my SP does nothing. It executes fine, but because of my protection it doesn't delete any records including the ones I'm trying to delete. So my question should have been. How to I pass a dynamic parameter to the SP using a pass-through query designed in the Query Designer and not writing up a whole bunch of code in VBA.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top