G
Gal
Hi
I am in the process of trying to convert an Access DB to ADP/SQL Server
2000 - learing as I go. All help gratefully appreciated!!!
I had a VBA routine which added various records to various tables which
I have re-written as a stored procedure, and, after calling the
procedure via a form in the ADP, I want to return the ID from the first
header record written.
The procedure does this when run in Query Analyser, but for some
reason, when called via VBA, (rst.Open SQL, cnn) the next line of code
claims (and I believe it!) that rst is now closed, so it won't give me
my single value! The message I get when trying to run rst.close is:
Operation is not allowed when the object is closed.
I stripped down the procedure to remove as much as necessary to make
the thing work in principle, and it seems that as soon as the proc
contains an INSERT statment, it won't return.
A pruned down (still failing) version of the procedure is as follows:
ALTER PROCEDURE dbo.usp_vItemsAdd
@CurrentUser varchar(50), @PO varchar(30),
@ReqBy varchar(30), @IssBy varchar(30),
@IndItemQty int, @Qty int, --IndItemQty is the number of INDIVIDUAL
ITEMS for STE or Plant
@Type varchar(1), @Prefix varchar(1), @StartNo bigint,
@ItemType bigint, @ItemValue money
AS
declare @SMUID bigint
declare @Counter bigint
--Add Stock Movement Header Record
INSERT INTO dbo.tblStockMovement
(PONumber, ReqBy, IssBy)
SELECT @PO, @ReqBy, @IssBy
--Store new SMUID from above
select @SMUID=@@Identity
SET @Counter = 1
WHILE (@Counter <= @IndItemQty)
begin
--Add Items to tblItems
INSERT INTO tblItems
(ItemCode, ItemType, ItemValue)
SELECT @Type +convert(varchar(10),@StartNo + @Counter - 1),
@ItemType, @ItemValue
SET @Counter = @Counter+1
end
SELECT @SMUID as LastID
I am in the process of trying to convert an Access DB to ADP/SQL Server
2000 - learing as I go. All help gratefully appreciated!!!
I had a VBA routine which added various records to various tables which
I have re-written as a stored procedure, and, after calling the
procedure via a form in the ADP, I want to return the ID from the first
header record written.
The procedure does this when run in Query Analyser, but for some
reason, when called via VBA, (rst.Open SQL, cnn) the next line of code
claims (and I believe it!) that rst is now closed, so it won't give me
my single value! The message I get when trying to run rst.close is:
Operation is not allowed when the object is closed.
I stripped down the procedure to remove as much as necessary to make
the thing work in principle, and it seems that as soon as the proc
contains an INSERT statment, it won't return.
A pruned down (still failing) version of the procedure is as follows:
ALTER PROCEDURE dbo.usp_vItemsAdd
@CurrentUser varchar(50), @PO varchar(30),
@ReqBy varchar(30), @IssBy varchar(30),
@IndItemQty int, @Qty int, --IndItemQty is the number of INDIVIDUAL
ITEMS for STE or Plant
@Type varchar(1), @Prefix varchar(1), @StartNo bigint,
@ItemType bigint, @ItemValue money
AS
declare @SMUID bigint
declare @Counter bigint
--Add Stock Movement Header Record
INSERT INTO dbo.tblStockMovement
(PONumber, ReqBy, IssBy)
SELECT @PO, @ReqBy, @IssBy
--Store new SMUID from above
select @SMUID=@@Identity
SET @Counter = 1
WHILE (@Counter <= @IndItemQty)
begin
--Add Items to tblItems
INSERT INTO tblItems
(ItemCode, ItemType, ItemValue)
SELECT @Type +convert(varchar(10),@StartNo + @Counter - 1),
@ItemType, @ItemValue
SET @Counter = @Counter+1
end
SELECT @SMUID as LastID