I have a stored procedure in SQL Server that accepts 6 parameters and will duplicate a quote and quote details. Depending upon the values checked, it makes an exact duplicate of an existing quote/quote details or changes the price by either a dollar amount or percentage amount. The field type in SQL Server is currency. The field type for the amount is a decimal(6,4) (I selected decimal because it could be a dollar amount or a percentage amount). When I run the stored procedure from SQL, it runs without errors. I am setting up an Access application that connects to this SQL Server. This is my SQL stored proc code:
Then in Access, I am taking values from text boxes and checkboxes to populate the parameters. This is my code from Access:
The problem I'm having is this error when I try to run the code from Access.
"The precision is invalid" and when I debug that error, it's on the cmd.Execute line. I think somewhere on the Parameters.Append for the @amount parameter, I need to add the Precision and Scale but I haven't figure out how to add that.
SQL:
ALTER PROCEDURE [dbo].[usp_DuplicateQuote]
@QuoteID INT, --quoteID
@quoteDate date, --quoteDate
@percent bit, --percent
@amount decimal(10,4), --priceChgAmt
@futureprice bit, --futurePrice
@pricechange bit --priceChange
AS
BEGIN
SET NOCOUNT ON;
IF OBJECT_ID('tempdb..#newQuote') IS NOT NULL
DROP TABLE #newQuote
SELECT q.[Quote Date], q.QuoteID, q.[Future Pricing], q.[Special Price], q.CustomerID,
q.Freight, q.Notes, q.[Nat'l Accounts], q.Nestle, q.Invalid as quote_invalid, d.[Div ID],
d.[Product ID], d.[$/lb], d.[$/roll], d.[Roll Width], d.[Roll Length], d.[Core ID], d.CustPartNumber,
d.ItemNotes, d.InternalNotes, d.EndUserID, d.Invalid as detail_invalid, d.[Cust Rebate], d.[EU Rebate],
d.[Nestle Alt Price $/lb]
INTO #newQuote
FROM dbo.Quotes q LEFT OUTER JOIN dbo.[Quotes Detail] d
ON q.QuoteID=d.QuoteID
WHERE q.QuoteID = @QuoteID
INSERT INTO Quotes ([Quote Date], [Future Pricing], [Special Price], CustomerID, Freight, Notes,
[Nat'l Accounts], Nestle, Invalid)
SELECT DISTINCT @quoteDate, q.[Future Pricing], q.[Special Price], q.CustomerID, q.Freight,
q.Notes, q.[Nat'l Accounts], q.Nestle, q.quote_invalid
FROM #newQuote q;
DECLARE @new_identity INT = @@IDENTITY;
IF @percent = 1
BEGIN
INSERT INTO [dbo].[Quotes Detail] ([QuoteID], [Div ID], [Product ID], [$/lb], [$/roll], [Roll Width],
[Roll Length], [Core ID], [CustPartNumber], [ItemNotes], [InternalNotes], [EndUserID], [Invalid],
[Cust Rebate], [EU Rebate], [Nestle Alt Price $/lb])
SELECT DISTINCT @new_identity, [Div ID], [Product ID], [$/lb]+([$/lb]*@amount), [$/roll], [Roll Width],
[Roll Length], [Core ID], [CustPartNumber], [ItemNotes], [InternalNotes], [EndUserID], [detail_invalid],
[Cust Rebate], [EU Rebate], [Nestle Alt Price $/lb]
FROM #newQuote
END
IF @percent = 0
BEGIN
INSERT INTO [dbo].[Quotes Detail] ([QuoteID], [Div ID], [Product ID], [$/lb], [$/roll], [Roll Width],
[Roll Length], [Core ID], [CustPartNumber], [ItemNotes], [InternalNotes], [EndUserID], [Invalid],
[Cust Rebate], [EU Rebate], [Nestle Alt Price $/lb])
SELECT DISTINCT @new_identity, [Div ID], [Product ID], [$/lb]+@amount, [$/roll], [Roll Width],
[Roll Length], [Core ID], [CustPartNumber], [ItemNotes], [InternalNotes], [EndUserID], [detail_invalid],
[Cust Rebate], [EU Rebate], [Nestle Alt Price $/lb]
FROM #newQuote
END
END
Then in Access, I am taking values from text boxes and checkboxes to populate the parameters. This is my code from Access:
Code:
Private Sub cmdDuplicateQuote_Click()
Dim quoteID As Integer
Dim quoteDate As Date
Dim percent As Byte
Dim priceChgAmt As Double
Dim futurePrice As Byte
Dim priceChange As Byte
If Me.NewRecord = True Then Exit Sub
quoteID = Form_frmDuplicateQuote.QuoteID_Textbox.Value
If Me!cboxFutureDate = True Then
quoteDate = Form_frmDuplicateQuote.txtFutureDAte.Value
futurePrice = True
Else
quoteDate = Date
futurePrice = False
End If
If Me!cboxPriceChange = True Then
priceChgAmt = Form_frmDuplicateQuote.txtPriceChange.Value
Else
priceChgAmt = 0
End If
If Me!cboxPercent = True Then
percent = True
Else
percent = False
End If
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=MSOLEDBSQL;" _
& "Server=CAMROMERE\SQLEXPRESS;" _
& "Database=innoviaSales;" _
& "Integrated Security=SSPI;" _
& "DataTypeCompatibility=80;"
conn.Open
Set cmd = New ADODB.Command
cmd.ActiveConnection = conn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "[dbo].[usp_DuplicateQuote]"
cmd.Parameters.Append cmd.CreateParameter("@quoteID", adInteger, adParamInput, 0, quoteID)
cmd.Parameters.Append cmd.CreateParameter("@quoteDate", adDate, adParamInput, 0, quoteDate)
cmd.Parameters.Append cmd.CreateParameter("@percent", adBoolean, adParamInput, 0, percent)
cmd.Parameters.Append cmd.CreateParameter("@amount", adDecimal, adParamInput, 0, priceChgAmt)
cmd.Parameters.Append cmd.CreateParameter("@futureprice", adBoolean, adParamInput, 0, futurePrice)
cmd.Parameters.Append cmd.CreateParameter("@pricechange", adBoolean, adParamInput, 0, priceChange)
cmd.Execute
conn.Close
The problem I'm having is this error when I try to run the code from Access.
"The precision is invalid" and when I debug that error, it's on the cmd.Execute line. I think somewhere on the Parameters.Append for the @amount parameter, I need to add the Precision and Scale but I haven't figure out how to add that.