Avatar of deer777
deer777
Flag for United States of America asked on

SQL Server/Access Front End Need to create a checkout process on primary key (product_number)

Working with an Access front end/SQL Server backend (linked tables).  Need to create process that will send a message to any user that tries to open the same product_number that is already checked out by another user at the same time.
Microsoft AccessSQL

Avatar of undefined
Last Comment
ste5an

8/22/2022 - Mon
ste5an

First of all: While this is not a hard task, it is a complicate one. Cause what happens when a user forgets to check-in again?

But the solution is pretty simple: Use a store procedure for this. Something like

CREATE PROCEDURE CheckoutItem ( @ProductNumber INT, @UserName SYSNAME OUTPUT )
AS
    SET NOCOUNT ON;
    SET XACT_ABORT ON;

	-- Constants.
    DECLARE @GENERIC_ERROR INT = -1; 
    DECLARE @NO_ERROR INT = 0;    

    BEGIN TRY 
        INSERT INTO Checkout ( ProductNumber ) VALUES ( @ProductNumber );
        RETURN @NO_ERROR;
    END TRY
    BEGIN CATCH
        SELECT @UserName = UserName 
        FROM Checkout
        WHERE ProductNumber = @ProductNumber;
        RETURN @GENERIC_ERROR;
    END CATCH;

Open in new window


with
CREATE TABLE Checkout
    (
        ProductNumber INT NOT NULL PRIMARY KEY ,
        UserName sysname
            DEFAULT ( SUSER_SNAME())
    );

Open in new window


and run this as pass-through query in Access to check-out your product.
deer777

ASKER
Can we include a message to the user trying to check out this product_name record that is already checked out in this stored procedure?
ASKER CERTIFIED SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes