ACC2002: Default Parameter Is Automatically Applied to Stored Procedures (279821)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q279821
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access project (.adp).

SYMPTOMS

When you use the Default keyword with a parameterized stored procedure, you are not prompted to provide a value for the parameter. Instead, the stored procedure automatically runs using the default value for the parameter.

RESOLUTION

To ensure that you are prompted with default values, use a SQL function instead of a stored procedure. To create a function with default values, follow these steps:
  1. Open the sample project NorthwindCS.adp.
  2. On the Insert menu, click Query.
  3. In the New Query dialog box, click Design In-Line Function, and then click OK.
  4. Click Close to close the Add Table dialog box without adding a table.
  5. On the View menu, click SQL View.
  6. Add the following Transact SQL in the SQL Text Editor:
          CREATE FUNCTION fnCustOrders
            (@EnterCustomerID varchar(5)='WOLZA')
          RETURNS TABLE
          AS
          RETURN (SELECT dbo.Customers.*
                  FROM dbo.Customers
                  WHERE (CustomerID = @EnterCustomerID))
     
    					
  7. On the File menu, click Save.
  8. Save the function as fnCustOrders, and then close it.
  9. Run the fnCustOrders function from the Database window.
  10. In the Enter Parameter Value dialog box, click the arrow, and then click <DEFAULT>.
  11. Click OK.
Note that the function returns the record where the CustomerID field equals "WOLZA", because that is the default value.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open the sample project NorthwindCS.adp.
  2. On the Insert menu, click Query.
  3. In the New Query dialog box, click Create Text Stored Procedure, and then click OK.
  4. Insert the following Transact SQL in the Text Editor:
          CREATE PROCEDURE spCustOrders
              @EnterCustomerID varchar(5) = 'WOLZA'	
          AS
              SELECT * FROM Customers WHERE CustomerID = @EnterCustomerID
     
    					
  5. Save the stored procedure as spCustOrders, and then close it.
  6. Run the spCustOrders stored procedure from the Database window.
Note that the stored procedure does not prompt you for a parameter. It immediately returns the record where CustomerID equals "WOLZA."

Modification Type:MajorLast Reviewed:11/6/2003
Keywords:KbClientServer kbprb KB279821